jasmine

changing global variable values in jasmine test

拟墨画扇 提交于 2019-12-11 04:59:02
问题 We use global variables like this for a jasmine test batch in our react app. global.serverVars = { language: 'en-us', context: 'testing', }; In one of the Spec which tests different languages, I want to change value of global.serverVars.language to nl-nl I am not sure how to achieve that. Any suggestion would be helpful. I mean, is it good practice to change global variable values on the fly or there is better approach? 回答1: Why don't you call your global variable in beforeEach or before

Angular 1.5 test component with jasmine

流过昼夜 提交于 2019-12-11 04:49:48
问题 I try test my component with Jasmine and Angular-mock, but I don't know how this do. This is my component var angular = require('angular'); 'use strict'; module.exports = angular .module('app.login.component.login', []) .component('login', { templateUrl: '/app/js/login/components/login.template.html', controller: LoginController }); LoginController.$inject = ['$state', 'Auth', 'messages']; function LoginController($state, Auth, messages) { var ctrl = this; ctrl.failMessage = messages.NO_AUTH;

ng serve throwing errors with simple ng new angular cli project

时光怂恿深爱的人放手 提交于 2019-12-11 04:48:28
问题 I am new to a angular-cli and have created an angular 2 project with ng new angular2 command. Now when I try to run it with ng serve , it just crashes with some errors. Log: ERROR in [default] C:\Users\user\desktop\angularcli\node_modules\@types\jasmine\index.d.ts:39:37 A parameter initializer is only allowed in a function or constructor implementation. ERROR in [default] C:\Users\user\desktop\angularcli\node_modules\@types\jasmine\index.d.ts:39:45 Cannot find name 'keyof'. ERROR in [default]

Unit testing promises in controllers in AngularJS

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:47:29
问题 We recently started incorporating promises in our controllers to handle multiple requests at the same time and it works in the app, but unit testing these has been proven to be more than difficult and I will I have a hard time grasping exactly what it is I'm missing. Following are two snippets that are very simplified on what I'm exactly trying to test. Controller: angular.module('testengine').controller('testController', [ '$scope', '$q', 'Api', function($scope, $q, Api) { $scope.getTest =

Test an async PipeTransform

左心房为你撑大大i 提交于 2019-12-11 04:38:58
问题 Context I have a basic PipeTransform , expect the fact that it is async. Why? because I have my own i18n service (because of parsing, pluralization and other constraints, I did my own) and it returns a Promise<string> : @Pipe({ name: "i18n", pure: false }) export class I18nPipe implements PipeTransform { private done = false; constructor(private i18n:I18n) { } value:string; transform(value:string, args:I18nPipeArgs):string { if(this.done){ return this.value; } if (args.plural) { this.i18n

How to print list of elements to console with protractor

荒凉一梦 提交于 2019-12-11 04:24:50
问题 I'm new to Stack Overflow. In my application I have to create a group and verify the group is created or not by searching the group in the list. If the group is in list, I have to open the chat box of that group. All this scenario should be automated using protractor. I'm new to protractor so could you please provide an explanation with the answer Trying to loop through group names to check if created. Tried simply printing group names in console, but still unsuccessful. Attempt in protractor

Cannot find module 'View' while testing react-native with Jasmine and TypeScript

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:22:16
问题 I'm trying to test a simple ("empty") react-native component using Jasmine. But I'm getting an error when I try to access any react-native component... In my configuration file (jasmine.json) I have: { "spec_dir": ".", "spec_files": [ "src/*.spec.tsx" ], "helpers": [ "./node_modules/ts-node/register.js" ] } My package.json "react": "16.0.0-alpha.12", "react-native": "0.45.1", "jasmine": "^2.6.0", "ts-node": "^3.3.0", My test script on package.json "test": "jasmine --config=jasmine.json" My

Testing an async function with Jasmine in Meteor

百般思念 提交于 2019-12-11 04:18:08
问题 I have looked at several other questions related to this on Stackoverflow, but I still can't seem to solve my problem. No matter what I seem to do, it seems that either Meteor.call doesn't get invoked, or if I can get it to be invoked (such as in the code sample below), no matter what the jasmine.DEFAULT_TIMEOUT_INTERVAL is set to, I continue to get the following error: Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. This is what

Angular 2 Observable testing Error: Cannot use setInterval from within an async zone test

我们两清 提交于 2019-12-11 04:13:35
问题 I'm trying to test a component, which uses a service that makes async http calls. The service returns an Observable, which the component subscribes on. Service code snippet: getRecentMachineTemperatures(_machine_Id): Observable<IDeviceReadings[]> { return this.http.get(TemperatureService.URL + _machine_Id) .map(response => { return response.json(); }) .map((records: Array<any>) => { let result = new Array<IDeviceReadings>(); if (records) { records.forEach((record) => { let device = new

angularjs unit test when to use $rootScope.$new()

ぃ、小莉子 提交于 2019-12-11 03:52:37
问题 I don't really understand when I should use the $rootScope = $rootScope .$new() in my angular unit tests. This snipped you see in many unit test examples. But in the following example that doesn't work: angular.module("app.root", []).factory("rootFct", function ($rootScope) { $rootScope.amount = 12; return { getAmount: function () { return ($rootScope.amount + 1); } } }); The associated unit Test doesn't work: describe('Amount Tests', function() { var rootFct, $rootScope; beforeEach(function(