From a2f518f5eab9425251db334eeb713d7a6614defa Mon Sep 17 00:00:00 2001 From: Stanislav Romanov Date: Fri, 16 Sep 2022 11:38:35 +0300 Subject: [PATCH] Add nullish coalescing helper --- app/helpers/nu-co.js | 6 ++++++ tests/integration/helpers/nu-co-test.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 app/helpers/nu-co.js create mode 100644 tests/integration/helpers/nu-co-test.js diff --git a/app/helpers/nu-co.js b/app/helpers/nu-co.js new file mode 100644 index 0000000..f29d136 --- /dev/null +++ b/app/helpers/nu-co.js @@ -0,0 +1,6 @@ +import { helper } from '@ember/component/helper'; + +// Nullish coalescing operator (??) +export default helper(function nuCo([arg1, arg2] /*, named*/) { + return arg1 ?? arg2; +}); diff --git a/tests/integration/helpers/nu-co-test.js b/tests/integration/helpers/nu-co-test.js new file mode 100644 index 0000000..579816b --- /dev/null +++ b/tests/integration/helpers/nu-co-test.js @@ -0,0 +1,17 @@ +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'meiliadmin/tests/helpers'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Helper | nu-co', function (hooks) { + setupRenderingTest(hooks); + + // TODO: Replace this with your real tests. + test('it renders', async function (assert) { + this.set('inputValue', '1234'); + + await render(hbs`{{nu-co this.inputValue}}`); + + assert.dom(this.element).hasText('1234'); + }); +});