Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Q js is undefined." while trying to resolve promise from aurelia-breeze in test method(karma+jasmine)

I am consistently getting an error while trying to resolve a promise from aurelia-breeze in a test method for an aurelia(typescript + breeze) application.

Testing framework used is karma+jasmine.

Version of the aurelia-breeze package is 1.0.0

Aurelia breeze makes use of es promise resolver instead of Q.js, but the test method is searching for Q.js to resolve the promise returned from breeze.

I have tried to add the Q library to the window object from the spec file. But the breeze.debug.js is trying to access the Q js from the window object before it is set in the spec file.

this didn't resolve the issue.

Please help me to solve this issue.

like image 534
Jithin Joy Avatar asked Feb 23 '16 14:02

Jithin Joy


1 Answers

Something like this should work:

import {configure as configureAureliaBreeze} from 'aurelia-breeze/index';
import {Container} from 'aurelia-dependency-injection';

const container = new Container();
configureAureliaBreeze({ container, globalResources: () => {} });

// ... tests ...

Breeze depends on Q for promises and jQuery for ajax. Aurelia-breeze shims both of those dependencies with ES6 promises and the aurelia http-client respectively. The code above effectively simulates what would happen in a .plugin('aurelia-breeze') call when running your aurelia application.

https://github.com/jdanyow/aurelia-breeze/blob/master/src/index.js#L15-L16

like image 184
Jeremy Danyow Avatar answered Sep 28 '22 12:09

Jeremy Danyow