Testing Twitter Flight Component with Jasmine - jasmine

Having issues running Jasmine Test with Twitter Flight. I'm using the jasmine-flight Plugin.
Error(s)
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
TypeError: this.Component is not a constructor
at Object.setupComponent (/frontend/bower_components/jasmine-flight/lib/jasmine-flight.js:44:23)
at Object.<anonymous> (/frontend/test/spec/component_ui/list-spec.js:5:10)
TypeError: Cannot read property 'trigger' of null
at Object.<anonymous> (/frontend/test/spec/component_ui/list-spec.js:19:19)
Test Component
describeComponent('javascript/component_ui/list-ui', function() {
'use strict';
beforeEach(function() {
jasmine.getFixtures().fixturesPath = 'base/test/fixtures';
this.setupComponent(
readFixtures('list.html'),
{
listRightMenu: '.list-right',
listSortSelector: '.list-sort',
}
);
});
it('Show menu when button is clicked', function() {
console.log(this);
this.component.trigger(this.component.attr.listSortSelector, 'click');
expect(this.component.attr.listRightMenu).toBeVisible();
});
});

Related

Failed: Cannot read property 'saveFullPageScreen' of undefined

I came across protractor-image-comparison and wanted to test it out.
I made a limited test based on the example of the website, and I get the error
Failed: Cannot read property 'saveFullPageScreen' of undefined.
The browser.imageComparison is not defined.
It's strange I get this error following the example. There is limited support for protractor so I ask it here.
----------------- test.spec.ts --------------
import { browser, } from 'protractor';
import { Urls, DashboardPage } from '../utils';
fdescribe('protractor-image-comparison desktop', () => {
beforeEach(async () => {
await Urls.gotoDashboard();
await DashboardPage.getVPoints();
// await DashboardPage.removeDebugInfo();
});
it('should save some screenshots', async() => {
// Save a full page screens
await .saveFullPageScreen('fullPage', { /* some options*/ });
});
it('should compare successful with a baseline', async() => {
// Check a full page screens
expect(await browser.imageComparison.checkFullPageScreen('fullPage', { /* some options*/ })).toEqual(0);
});
});
-------------- part of jasmine.ts ---------------
plugins: [
{
// The module name
package: 'protractor-image-comparison',
// Some options, see the docs for more
options: {
baselineFolder: join(process.cwd(), './baseline/'),
formatImageName: `{tag}-{logName}-{width}x{height}`,
screenshotPath: join(process.cwd(), '.tmp/'),
savePerInstance: true,
autoSaveBaseline: true,
blockOutToolBar: true,
clearRuntimeFolder: true,
// ... more options
},
},
],
Failures:
1) protractor-image-comparison desktop should save some screenshots
Message:
Failed: Cannot read property 'saveFullPageScreen' of undefined
Stack:
TypeError: Cannot read property 'saveFullPageScreen' of undefined
at Object.<anonymous> (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:119:83)
at step (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:75:27)
at Object.next (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:24:53)
at c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:17:71
at new Promise (<anonymous>)
at __awaiter (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:3:12)
at UserContext.<anonymous> (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:110:16)
at c:\projects\vital10-frontend\node_modules\jasminewd2\index.js:112:25
at new ManagedPromise (c:\projects\vital10-frontend\node_modules\selenium-webdriver\lib\promise.js:1077:7)
at ControlFlow.promise (c:\projects\vital10-frontend\node_modules\selenium-webdriver\lib\promise.js:2505:12)
From: Task: Run it("should save some screenshots") in control flow
at UserContext.<anonymous> (c:\projects\vital10-frontend\node_modules\jasminewd2\index.js:94:19)
at c:\projects\vital10-frontend\node_modules\jasminewd2\index.js:64:48
at ControlFlow.emit (c:\projects\vital10-frontend\node_modules\selenium-webdriver\lib\events.js:62:21)
at ControlFlow.shutdown_ (c:\projects\vital10-frontend\node_modules\selenium-webdriver\lib\promise.js:2674:10)
at c:\projects\vital10-frontend\node_modules\selenium-webdriver\lib\promise.js:2599:53
From asynchronous test:
Error
at Suite.<anonymous> (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:109:5)
at Object.<anonymous> (c:\projects\vital10-frontend\e2e\jasmine\image_compair\test.spec.ts:93:1)
at Module._compile (internal/modules/cjs/loader.js:868:30)
at Module.m._compile (c:\projects\vital10-frontend\node_modules\ts-node\src\index.ts:392:23)
at Module.m._compile (c:\projects\vital10-frontend\node_modules\ts-node\src\index.ts:392:23)
at Module._extensions..js (internal/modules/cjs/loader.js:879:10)
According to the docs you are missing browser.imageComparison before .saveFullPageScreen

How to send the success of a test to testingBot from a Protractor project?

Following the testingBot example for protractor-based projects I got this code
var TestingBot = require('testingbot-api');
describe('Protractor Demo App', function () {
var tb;
beforeEach(function () {
tb = new TestingBot({
api_key: "master_key",
api_secret: "secret_007"
});
});
afterEach(function () {
browser.getSession().then(function (session) {
tb.updateTest({
'test[success]': true/*where do I get this 'test[success]' attribute? */
}, session.getId(), function () {
console.log("Hi! :D");
});
})
});
it('should have a title', function () {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
I need to send the success of the test back through the tb.updateTest() but I don't know where I get the value of a passed or failed test. For now the value is a static true. I'd appreciate a jasmine approach too.
You can use a custom reporter with Jasmine.
There you can hook into specDone or suiteDone which has a result parameter, containing the test's success state.
You can then use this state to write a custom report or send it to somewhere else.

AngularJS Testing using Jasmine-Karma

I have a factory service inside a folder,,,i have mentioned the path in karma.conf.js file correctly and added the angular-mocks before that..But
if i try to load a factory/service which is not available in that folder then Unknown provider error is thrown
If i include the correct factory service then am not getting any error
But if i try to call a method in that factory/service,then the mocked service object is undefined and am getting cannot read a function from undefined error message..
I couldn't figure out why...can any1 help me in this issue..
Spec.js
describe('dfgh', function () {
var mockService,httpBackend;
beforeEach(function () {
module('app');
});
beforeEach(function () {
inject(function ($httpBackend, _familyService_) {
mockService = _familyService_;
httpBackend = $httpBackend;
});
});
it('Factory Service Testing', function () {
/// Code here
});
});
FamilySvc.js
(function() {
'use strict';
angular.module('app')
.factory('familyService', familyService);
familyService.$inject = ['$rootScope', '$http', '$q', 'service2', 'service3'];
function familyService() {
var a="Some String";
return a;
}
}());
Karma.conf.js
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'app/*.js', --> Holds FamilySvc.js
'tests/*.*' -- >holds Spec.js
],

Show Modal on AngularJS $httpProvider: responseError

We need to hookup a Modal with a generic message on our failed Ajax calls in AngularJS.
i was able to intercept the error on the app.config part, but from there i am unable to import the $modal or the $scope to show the modal. What i got working so far is creating a function on my global scope and add the opening of the modal in my app.run:
var showGeneralException = function () { };
var app= angular.module('myApp', ['ui.bootstrap'])
.run(function ($rootScope, $modal) {
showGeneralException = function () {
var exceptionModel = $modal.open({
templateUrl: 'generalException',
controller: 'exceptionModals',
});
};
});
app.config(function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'responseError': function (rejection) {
showGeneralException();
}
};
});
});
When i perform it this way a modal opens but i get a not found exception in my modal and following errors in my debug console:
TypeError: Unable to get value of the property 'data': object is null or undefined
LOG: WARNING: Tried to load angular more than once.
LOG: WARNING: Tried to load angular more than once.
LOG: WARNING: Tried to load angular more than once.

Expected spy but got function error message with Sinon stubs?

I have the following test suite:
describe('rendering Bundle View', function () {
beforeEach(function () {
this.view = new Backbone.View();
this.renderStub = Sinon.stub(this.view, 'render', function () {
this.el = document.createElement('div');
return this;
});
this.view.render();
});
it('should have called render once', function () {
console.info('RENDERRRR' + (typeof this.renderStub));
expect(this.renderStub.calledOnce).toBe(true); // this passes
expect(this.renderStub).toHaveBeenCalled(); // this fails
});
});
Why does the first expect statement pass but the second fail? The second gives the error message: expected Spy but got Function even though Sinon stubs implement the spy API so it should return a spy??
figured it out. I think its because I was using a Sinon spy with a jasmine function that expected a jasmine spy hence it didn't allow me to use Sinon expect statements

Resources