Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20603] Should.js is not working for ti.mocha

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-12-12T20:25:54.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterGourav
AssigneeChee Kiat Ng
Created2016-03-14T14:09:11.000+0000
Updated2016-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

Comments

  1. Sharif AbuDarda 2016-03-14

    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.
  2. Gourav 2016-03-15

    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.
  3. Sharif AbuDarda 2016-03-20

    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.
  4. Naga harish M 2016-03-29

    Same issue for me. Please help on this.
  5. Sharif AbuDarda 2016-12-12

    Hello, This issue is fixed in SDK 6.0.0.GA. I just tested it in Android 6.0.1 device. Verified:
       Operating System
         Name                        = Mac OS X
         Version                     = 10.11.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       Node.js
         Node.js Version             = 4.2.2
         npm Version                 = 2.14.7
       Titanium CLI
         CLI Version                 = 5.0.10
       Titanium SDK
         SDK Version                 = 6.0.0.GA
         Target Platform             = android
       
    Output:
       [INFO] :     app.js
       [INFO] :       #myWindow
       [INFO] :         o exists: 
       [INFO] :         + exists 
       [INFO] :         o has Ti.UI.Window functions: 
       [INFO] :         + has Ti.UI.Window functions 
       [INFO] :         o has dimensions equal to the device: 
       [INFO] :         1) has dimensions equal to the device
       [INFO] :       #myView
       [INFO] :         o exists: 
       [INFO] :         + exists 
       [INFO] :         o has Ti.UI.View functions: 
       [INFO] :         + has Ti.UI.View functions 
       [INFO] :         o is a child of window: 
       [INFO] :         + is a child of window 
       [INFO] :         o view has same dimensions as window: 
       [INFO] :         + view has same dimensions as window 
       [INFO] :    
       [INFO] :   
       [INFO] :     6 passing (321ms)
       

JSON Source