Skip to content

Commit

Permalink
Add a better test for the extraCliArgs option
Browse files Browse the repository at this point in the history
This uses testdouble.js to spy on the `ember` call that is done by `emberNew`.
  • Loading branch information
Windvis committed Dec 10, 2024
1 parent f4ff8d5 commit dccf643
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
8 changes: 0 additions & 8 deletions tests/acceptance/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ describe('Acceptance: helpers', function () {
expect(fs.existsSync(addonPath)).to.equal(true);
});
});

it('emberNew - extraCliArgs', () => {
return emberNew({ extraCliArgs: ['--typescript', '--no-welcome']})
.then(() => {
const appPath = path.resolve(process.cwd(), 'app');
expect(fs.existsSync(appPath)).to.equal(true);
});
});
});

describe('emberGenerateDestroy', () => {
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/ember-new-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const setupTestHooks = require('../../lib/helpers/setup');

const chai = require('../../chai');
const expect = chai.expect;
const td = require('testdouble')

let ember;

describe('Unit: emberNew', function () {
setupTestHooks(this);

afterEach(() => {
td.reset();
ember = undefined;
});

it('emberNew - extraCliArgs', () => {
const originalEmber = require('../../lib/helpers/ember.js');
ember = td.replace('../../lib/helpers/ember.js');

// "spy" on the original ember function.
// testdouble.js doesn't have built-in support for this because it considers it a bad practise:
// https://github.com/testdouble/testdouble.js/issues/512#issuecomment-1527511338
td.when(ember(td.matchers.contains('--typescript', '--no-welcome'), td.matchers.anything())).thenDo((...args) => {
return originalEmber(...args);
});

// We require emberNew here so the testdouble dependency replacement works
const emberNew = require('../../lib/ember-new');

return emberNew({ extraCliArgs: ['--typescript', '--no-welcome'] })
.then(() => {
// If we get here that means our testdouble matcher worked and things were called as expected.
expect(true).to.be.true;
});
});
});

0 comments on commit dccf643

Please sign in to comment.