Add nullish coalescing helper
This commit is contained in:
parent
8ef5d62191
commit
a2f518f5ea
2 changed files with 23 additions and 0 deletions
6
app/helpers/nu-co.js
Normal file
6
app/helpers/nu-co.js
Normal 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;
|
||||
});
|
||||
17
tests/integration/helpers/nu-co-test.js
Normal file
17
tests/integration/helpers/nu-co-test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue