question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to "require" a supporting class within a unit test, given the generated code from aurelia-cli.

See original GitHub issue

I’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 called utils as a sibling to unit
  • Create a new file within utils called testHelper.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:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AStokercommented, Oct 25, 2016

BTW, my testHelper.js is as follows (since I’m on ESNext)

export default class TestHelper{
    Name = 'test';
}
0reactions
AStokercommented, Oct 25, 2016

Glad you got it working! Happy to help

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found