Add nullish coalescing helper

This commit is contained in:
Stanislav Romanov 2022-09-16 11:38:35 +03:00
parent 8ef5d62191
commit a2f518f5ea
2 changed files with 23 additions and 0 deletions

6
app/helpers/nu-co.js Normal file
View file

@ -0,0 +1,6 @@
import { helper } from '@ember/component/helper';
// Nullish coalescing operator (??)
export default helper(function nuCo([arg1, arg2] /*, named*/) {
return arg1 ?? arg2;
});

View file

@ -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');
});
});