karma-jasmine

How can I get karma browser's to use a dark theme?

﹥>﹥吖頭↗ 提交于 2019-12-11 17:24:46
问题 I'm starting to use karma in an Angular app and would like to change the browser theme to be dark. I wanted to know if there was anywhere in the configuration file I can just inject simple css or use add a js file to inject these styles. e.g. karma-styles.js var css = ` html * { background-color: black !important; color: white !important; } .html-reporter .failures .spec-detail .description { background-color: #b03911 !important; } `, head = document.head || document.getElementsByTagName(

angular JS unit testing a controller

痞子三分冷 提交于 2019-12-11 16:23:07
问题 I have a controller like this (function(){ var app = angular.module('app', []); app.directive('test', function(){ return { restrict: 'E', templateUrl: 'test.html', controller: ['$scope', function ($scope) { $scope.password = ''; $scope.grade = function() { var size = $scope.password.length; if (size > 8) { $scope.strength = 'strong'; } else if (size > 3) { $scope.strength = 'medium'; } else { $scope.strength = 'weak'; } } }]; }); I am writing a unit test to this controller describe(

RegExp.test not giving correct result

梦想与她 提交于 2019-12-11 16:09:07
问题 In the following code, I pass a FormControl which contains a password. I expect that when the password is aA1[11] , the RegExp.test method should return false but it returns true! Why my code is returning null instead of error object { validatePassword: { valid: false, message: 'password must contain 1 small-case letter [a-z], 1 capital letter [A-Z], 1 digit[0-9], 1 special character and the length should be between 6-10 characters' } Shouldn't this forward look up fail the match (?=.*[!@#$%^

TypeError: Failed to resolve module specifier “@open-wc/testing”. Relative references must start with either “/”, “./”, or “../”

折月煮酒 提交于 2019-12-11 15:53:45
问题 I am trying to find some good way to unit test m y vanilla webcomponents and I am trying this approach open-wc and I am getting error mentioned above my-component-test.js import { html, fixture, expect, } from '@open-wc/testing'; import { MyComponent } from "../src/my-component.js"; describe("simple test", () => { it("test", async () => { const el = await fixture("<my-component></my-component>"); expect(el.success).to.be.false; }); }); relevant part from package.json "scripts": { "test":

Testing *ngIf show/hide component dependent on data

独自空忆成欢 提交于 2019-12-11 15:39:56
问题 I am trying to test a show/hide data component. Without its data (currently undefined), a simple block of text is displayed. However when i then feed the component with data, the first block should become hidden whilst the second block that consists of the list of data in a table should become visible, however null is being returned (withDataBlock). Therefore tests errors on the last expect of the test, even though i add fixture.detectChanges() method beforehand. component: import { Component

Cannot read property of undefined in angular karma test

寵の児 提交于 2019-12-11 15:36:27
问题 I am testing a service function which makes numerous $http.get() calls. The actual function under test returns a promise. Currently, the test is failing with response is undefined . Here is the test: it('should return the list of catalogues', inject(function ($q, bookService) { var list; var deferred = $q.defer(); var promise = deferred.promise; promise.then(function (response) { list = response.success; // Cannot read property 'success' of undefined }); bookService.getCatalogues().then

Angular testing Service method with window.location.replace

点点圈 提交于 2019-12-11 15:31:43
问题 In my Angular 4 application, I need to test a method of a Service which at some point it calls a private method of the same service having: window.location.replace(url); When the test reach that line, the karma-runner browser gets redirected to the url which of course is not what I want. If I try to spy it, I get: Error: <spyOn> : replace is not declared writable or has no setter How can I correctly test my method? 回答1: location object is read-only property, and its properties are read-only

Jasmine/Karma testing Angular 5 HTTP responses

梦想的初衷 提交于 2019-12-11 15:15:14
问题 I'm totally new to TDD and I'm trying to debug a big Angular 5 application we're working in, at the company. The app is working well, but now I have to implement tests, and I'm learning this stuff while I create the most basic and starter ones. I wrote this stuff already for the main module, just for trying this tooling: describe('AppComponent', () => { let httpClientSpy: { get: jasmine.Spy } let dataReq: DataRequester; let queryBuilder: PanelQueryBuilder; let query: DataQuery; beforeEach

Angular2, TypeScript, PhantomJS - Can't find variable: Audio

纵然是瞬间 提交于 2019-12-11 14:01:57
问题 PhantomJS doesn't support HTML5 Audio tags, which is making it difficult to test my Angular2 app. I've looked around for a solution, but unfortunately I haven't been able to figure out a way to mock the Audio object or somehow get around this. I have an Angular2 service that looks like this: import {Injectable} from 'angular2/core'; @Injectable() export class MyService { var snd; constructor() { this.snd = new Audio('Assets/sound.wav'); } simpleFunction() { return true; } } My test looks like

Can't find variable: loadFixtures

老子叫甜甜 提交于 2019-12-11 13:22:09
问题 I am using karma, jasmine and phantomjs for my project and when I am executing start karma; I am getting following error: PhantomJS 1.9.7 (Linux) View:: Login guestRegistration Should call the guestRegistration event when btn-grey is clicked FAILED ReferenceError: Can't find variable: loadFixtures at /apps/devops/jenkins/home/jobs/UIMod-Jasmine-Karma/workspace/WebContent/test/javascript/spec/login.view.spec.js:84 ReferenceError: Can't find variable: spyOnEvent at /apps/devops/jenkins/home