matthewjh / jasmine-promises Goto Github PK
View Code? Open in Web Editor NEWReturn Promises from your Jasmine tests, rather than having to manually call `done` and `done.fail`
License: MIT License
Return Promises from your Jasmine tests, rather than having to manually call `done` and `done.fail`
License: MIT License
I'm getting an error when I try and use jasmine-promises.
The error is:
Error: Cannot find module './patch' from '[PATH TO NODE_MODULES]/node_modules/jasmine-promises/dist'
I see the call to require patch.js in the code, but no such file exists in dist/
I'm sure it's something simple I'm doing wrong.
Any help would be much appreciated.
When running against Jasmine 2.3.2, at call-site of require('jasmine-promises')
.
Selenium standalone server started at http://10.32.64.38:59425/wd/hub
TypeError: Cannot read property 'interface' of undefined
at patchInterfaceFn (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:71:21)
at Object.apply (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:83:3)
at Object.<anonymous> (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:15:7)
at Object../patch (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:17:4)
at s (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:1:316)
at e (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:1:487)
at Object.<anonymous> (F:\build\node_modules\jasmine-promises\dist\jasmine-promises.js:1:505)
Versions:
$ npm ls jasmine jasmine-promises protractor
[email protected] F:\build
├── [email protected]
└── [email protected]
└─┬ [email protected]
└── [email protected]
There is one cases your library do not really address or I couldn't find the way to address it with it:
it('my test', function() {
var promise = sut.methodUnderTest()
.catch(function(err) {
expect(err.message).toBe('expected error message');
});
return promise;
});
if promise
is a fullfilled promise, the test pass.
This is very common: I want to check my function is returning an error (in the form of a Promise.reject()
on some condition and also check error message being of some type.
Using your library it doesn't matter what you check, if your method INCORRECTLY return a fullfilled promise value the test pass.
Is it the only way to implement then()
in the test and call fail()
with a reason or is there a better way in the library?
I'm trying to make use of jasmine-promises in a promise-heavy codebase. Our current practice is to expect that the promise is resolved (or rejected as appropriate) inside a promise.finally handler (we're using Q.js promises). It can be hard to track down promise failures when this occurs. jasmine-promises looks like it will simplify the tests and ensure that errors are reported.
We have some complicated fixtures that need extensive set-up. We attach data and mock objects/spies to the fixture by using the object that jasmine passes to the beforeEach
function, then subsequently to the it
function, as the this
pointer.
After enabling jasmine-promises, all existing tests that make use of this
are failing with a TypeError: Cannot set property 'xxx' of undefined
error.
This is a blocker preventing us from using jasmine-promises at all.
Minimum reproducible case:
describe('fixture', function() {
beforeEach(function() {
this.field = 'value';
});
it('should set `this` correctly', function() {
expect(this.field).toEqual('value');
});
});
Without loading jasmine-promises the test passes. After loading jasmine-promises, you get:
Chrome 48.0.2564 (Windows 7 0.0.0) fixture should set `this` correctly FAILED
TypeError: Cannot set property 'field' of undefined
at [...]/jasmine-promises.unit.js:6:24
at Object.arguments.(anonymous function) ([...]/node_modules/jasmine-promises/
dist/jasmine-promises.js:39:23)
at Object.arguments.(anonymous function) ([...]/node_modules/jasmine-promises/
dist/jasmine-promises.js:51:11)
TypeError: Cannot read property 'field' of undefined
at [...]/jasmine-promises.unit.js:10:24
at Object.arguments.(anonymous function) ([...]/node_modules/jasmine-promises/
dist/jasmine-promises.js:39:23)
The behaviour of the this
pointer is documented at Jasmine 2.2 introduction.js - The this keyword
Version: v0.4.2
When promise fails i get stack trace like which is really anoint because you always have to scroll up a lot to see where did it failed
webpack:///src/features/tt-select/tt-select_test.js:68:53 <- src/features/tt-select/tt-select_test.js:112:54
node_modules/jasmine-promises/dist/jasmine-promises.js:83:36
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
node_modules/jasmine-promises/dist/jasmine-promises.js:95:17
...
Hi great work on this module!
I get strange stack traces when a test fails. Here's an example
Error: index must be defined in /myProject/src/entities/Face.js (line 9)
/myProject/src/entities/Face.js:9:1841
/myProject/tests/entities/FaceSpec.js:21:82
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:35:34
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
/myProject/node_modules/jasmine-promises/dist/jasmine-promises.js:47:15
..... this continues for another 40 lines ....
Any idea how to limit this?
Unfortunately it looks like this library doesn't function when run under Node.js.
I suspect this has something to do with the way in which you're attempting to patch the global
object - specifically the global.jasmineRequire
object.
Currently I'm working around the issue by "mocking" the jasmineRequire.interface
function with a no-op. This seems to address the problem, however it would be good to include a check in the library itself instead.
global.jasmineRequire = {
interface: function() {}
};
require('jasmine-promises');
TypeError: Cannot read property 'interface' of undefined
at patchInterfaceFn (D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:68:21)
at apply (D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:80:3)
at Object.<anonymous> (D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:12:18)
at Object.__dirname.1../patch (D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:14:4)
at s ((D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:1:316)
at e ((D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:1:487)
at Object.<anonymous> (D:\...\node_modules\jasmine-promises\dist\jasmine-promises.js:1:505)
at Module._compile (module.js:425:26)
at Object.Module._extensions..js (module.js:432:10)
at Module.load (module.js:356:32)
Jasmine 2.7 has support for promises built in
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.