[TIMOB-20603] Should.js is not working for ti.mocha
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-12-12T20:25:54.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Gourav |
Assignee | Chee Kiat Ng |
Created | 2016-03-14T14:09:11.000+0000 |
Updated | 2016-12-12T20:25:54.000+0000 |
Description
Hi,
I tried to utilise ti.mocha in our application.
It works with the very basic example.
But as suggested by tonylukasavage, we are trying on consume should.js for assertion.
But it's throwing error always.
In one of the comments from the blog its mention that we have to use only the should.js file and not the complete SDK.
http://tonylukasavage.com/blog/2014/01/13/ti-mocha-mocha-testing-support-for-titanium/
Please look into in this and let us know asap.
PFB error logs for the same.
Script Error {
[ERROR] : column = 15;
[ERROR] : line = 26;
[ERROR] : message = "Can't find variable: window";
[ERROR] : sourceURL = "file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js";
[ERROR] : stack = "file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js:26:15\ns@file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js:14:25\ne@file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js:22:41\nfile:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js:24:2\nglobal code@file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/should.js:1912:70\nrequire@[native code]\nfile:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/test/app_test.js:1:139\nglobal code@file:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/test/app_test.js:41:70\nrequire@[native code]\nfile:///Users/Nikesh/Library/Developer/CoreSimulator/Devices/1B9238A9-7066-4BE5-9CA7-177D26014FC2/data/Containers/Bundle/Application/72590E8D-686D-4932-B2FE-113A5FD68245/behaveExample.app/alloy/controllers/index.js:65:16";
[ERROR] : }
[ERROR] : Script Error Module "should" failed to leave a valid exports object
[ERROR] : Script Error Module "test/app_test" failed to leave a valid exports object
[ERROR] : ErrorController is up. ABORTING showing of modal controller
[ERROR] : ErrorController is up. ABORTING showing of modal controller
Hello, Please provide a regeneratable sample code for the issue you have mentioned above. We will try it in our environment if the issue is regeneratable or not. Please use the latest SDK 5.2.0.GA for your test. Also please provide a complete list of steps to follow. Thanks.
Hi, As mentioned in the document by tonylukasavage, I am using the same basic example. At Index.js require('ti-mocha'); // create a basic UI var win = Ti.UI.createWindow({ backgroundColor: '#fff', fullscreen: false, exitOnClose: true, id: 'myWindow' }); var view = Ti.UI.createView({ height: Ti.UI.FILL, width: Ti.UI.FILL, backgroundColor: '#a00', id: 'myView' }); win.add(view); setTimeout(function(){ require('test/app_test')(win, view); },100); // For app_test var should = require('should'); module.exports = function(win, view) { describe('app.js', function() { describe('#myWindow', function() { it('exists', function() { should.exist(win); win.id.should.equal('myWindow'); }); it('has Ti.UI.Window functions', function() { should(win.open).be.a.Function; should(win.close).be.a.Function; if (Ti.Platform.name === 'iPhone OS') { should(win.hideTabBar).be.a.Function; } }); it('has dimensions equal to the device', function() { win.size.height.should.equal(Ti.Platform.displayCaps.platformHeight); win.size.width.should.equal(Ti.Platform.displayCaps.platformWidth); }); }); describe('#myView', function() { it('exists', function(){ should.exist(view); view.id.should.equal('myView'); }); it('has Ti.UI.View functions', function() { // should(view.add).be.a.Function; should(win.open).be.a.Function; // will work as expected }); it('is a child of window', function() { win.children.length.should.equal(1); should.exist(win.children[0]); win.children[0].id.should.equal('myView'); }); it('view has same dimensions as window', function(){ view.size.height.should.equal(win.size.height); view.size.width.should.equal(win.size.width); }); }); }); // run the tests mocha.run(); Can you please check it now.
Hello, I was able to regenerate the issue using the instruction to use should.js with ti-mocha in here http://tonylukasavage.com/ti-mocha/. I post a comment in the blog. I would suggest you follow the blog for response. Thanks.
Same issue for me. Please help on this.
Hello, This issue is fixed in SDK 6.0.0.GA. I just tested it in Android 6.0.1 device. Verified:
Output: