Unable to "require" a supporting class within a unit test, given the generated code from aurelia-cli.
See original GitHub issueI’m submitting a bug report
- Library Version: 0.21.0
Please tell us about your environment:
- Operating System: OSX 10.x/Windows 7
- Node Version: 4.4.3/5.4.0
- NPM Version: 3.10.9/3.9.1
- Browser: Only targeting Chrome at this time, however I suspect this will fail in other browsers.
- Language: all
Current behavior:
Unable to “require” a supporting class within a unit test, given the generated code from aurelia-cli.
The steps below have been applied to this repository
Following these steps I am unable to execute a test within the new aurelia cli framework.
- run
au new
- Accept all defaults except choose Typescript (however this fails with ESNext as well)
- Add new folder under
test
calledutils
as a sibling tounit
- Create a new file within
utils
calledtestHelper.ts
export TestHelper {
Name : string;
}
- Modify
app.spec.ts
to include the new utility class and use it within the test
import {App} from '../../src/app';
import {TestHelper} from "../utils/testHelper";
describe('the app', () => {
it('says hello', () => {
let h = new TestHelper();
h.Name = "John";
expect(h.Name).toBe("John");
expect(new App().message).toBe('Hello World!');
});
});
- Add the utils folder to the files configuration object of karma within
karma.config.js
let testSrc = [
{ pattern: 'test/utils/**/*.ts', included: false},
{ pattern: project.unitTestRunner.source, included: false },
'test/aurelia-karma.js'
];
- Add the utils folder to the preprocessors configuration object of karma within
karma.config.js
preprocessors: {
[project.unitTestRunner.source]: [project.transpiler.id],
['test/utils/**/*.ts']: [project.transpiler.id]
},
- run
au build
- run
au test
- You will receive the following error:
λ au test
Starting 'unit'...
24 10 2016 15:11:42.954:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
24 10 2016 15:11:42.971:INFO [launcher]: Starting browser Chrome
24 10 2016 15:11:43.969:INFO [Chrome 53.0.2785 (Windows 7 0.0.0)]: Connected on socket -rw81aF6Glx1RWjVAAAA with id 8644146
24 10 2016 15:11:44.149:WARN [web-server]: 404: /base/test/utils/helper
Chrome 53.0.2785 (Windows 7 0.0.0) ERROR
Uncaught Error: Script error for "C:/git/aurelia-app/test/utils/helper", needed by: C:/git/aurelia-app/test/unit/app.spec.js
http://requirejs.org/docs/errors.html#scripterror
at C:/git/aurelia-app/scripts/vendor-bundle.js:3763
{ uid: 0,
name: 'unit',
branch: false,
error: 1,
duration: [ 2, -497867396 ],
time: 1477336304256 }
1
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Unable to use helper classes within unit tests of a bundled ...
Using the aurelia cli and the default tasks that are included, I am unable to leverage helper classes that are located within the...
Read more >Aurelia - Eric L. Anderson
This week we are going to add an Aurelia project that will utilize the contacts API we created a few weeks ago using...
Read more >Unit testing Aurelia service code
This article gives a basic introduction to testing these classes using the Aurelia CLI. What libraries are included in the CLI, ...
Read more >aurelia/Discuss - Gitter
I created a new project with the CLI, and now I'm starting to drop ... is still being supported, but isn't a first-class...
Read more >How To Use Nswag With ASP.NET Core And Generate Client ...
NET Core And Generate Client Code With Nswag Studio ... Angular 2+, Aurelia, KnockoutJS and more) and other platforms, written in C#.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
BTW, my
testHelper.js
is as follows (since I’m on ESNext)Glad you got it working! Happy to help