karma-jasmine

Karma tests using a Docker image of Chrome

寵の児 提交于 2019-12-24 04:41:14
问题 For tests on CI server I want to use an image of Chrome instead of PhantomJS. I can do this with and without puppeteer but both require me to install chrome-stable package on the server. Thus I want a more lightweight method hence the use of the docker image. For Karma, according to the docs, I must specify a script for the browser if i want to use a custom browser. Also Karma will pass 1 argument to this script, the url. For this requirement I also pulled the browserless docker image

Jasmine angular unit test 'Cannot read 'property' of undefined

烈酒焚心 提交于 2019-12-24 02:06:20
问题 I have just started learning angular unit testing. However, this test on a function with http call fails. I have pin pointed the problem but however I am not being able to fix it. I know it's some simple issue Controller //Get data from URL vm.getJson = function() { var url = 'https://www.reddit.com/r/worldnews/new.json', count = 0; $http.get(url).success(function(response) { console.log(response); for (var i = 0; i < response.data.children.length; i++) { vm.data.push(response.data.children[i

Do I have to inject the service in the unit test if I cal testBed.get() previously?

扶醉桌前 提交于 2019-12-24 00:46:07
问题 I have a service which I'm consuming in my angular 2 unit test. I call the service in the beforeEach block first with TestBed.get() Example : beforeEach(() => { fixture = TestBed.createComponent(ConfigComponent); component = fixture.componentInstance; service = TestBed.get(ConfigService); fixture.detectChanges(); }); I then use this service in the unit test like this: Example : it('should do something', inject([ConfigService], (configService) => { // code here })); Do I need to inject the

Angular2 and Karma Issue

拈花ヽ惹草 提交于 2019-12-24 00:44:33
问题 I have a problem with tests - when running multiple tests one of them fails, but when I isolate them and run one at the time, they all pass. Tests are basic placeholders (I'm working on seed project) and typically look like this: import {inject, injectAsync, TestComponentBuilder, beforeEachProviders} from 'angular2/testing' import {describe, ddescribe, it, iit, expect} from 'angular2/testing' import {provide} from 'angular2/core' import {PeopleComponent} from './people.component' describe(

Karma Test With angular 6

社会主义新天地 提交于 2019-12-23 16:43:41
问题 I am tring to run test of angular using npm ng test but the problem is that chrome start and not stop after test finish so I used : ng test --watch=false but that cause error "Chrome 69.0.3497 (Linux 0.0.0) ERROR" which make chrome timeout I am trying to run that on continuous deployment server so this error cause fail in the process any idea how to stop that 回答1: You can avoid this under unix based system using the Headless chrome It's a way to run the Chrome browser in a headless

Cannot install jasmine-core on Windows 7 / OSX

心已入冬 提交于 2019-12-23 16:04:40
问题 I am trying to install karma-jasmine on Windows 7 / Git Bash, according to these guidelines: http://karma-runner.github.io/0.13/intro/installation.html However, the installation fails for jasmine-core : $ npm install karma-jasmine karma-chrome-launcher --save-dev npm WARN install Couldn't install optional dependency: Unsupported ngut@1.0.0 g:\SW Engineering\ngUT ├── UNMET PEER DEPENDENCY jasmine-core@* ├─┬ karma-chrome-launcher@0.2.2 │ ├─┬ fs-access@1.0.0 │ │ └── null-check@1.0.0 │ └─┬ which

Angular2 test fail when mocking a service

旧城冷巷雨未停 提交于 2019-12-23 12:39:07
问题 Trying to test a component with a service dependency that call rest API, made a mocked version of the service, with a class that extends the real service. Now if I override the provider with the mocked one, weird error comes out of karma reporter, first 404 for 2 not existing files (that really should not exist) and then "{originalErr: {}}". I mean at least tell me what I've done wrong :) My test suit: describe('App: HeaderComponent', () => { it('should get categories on initialization',

Angular 2 Testing - Component Instance is undefined

ぐ巨炮叔叔 提交于 2019-12-23 12:33:05
问题 I have a problem in testing in Angular 2. describe('Spinner Component', () => { beforeEach(() => TestBed.configureTestingModule({ declarations: [SpinnerComponent] }).compileComponents()); beforeEach(() => { fixture = TestBed.createComponent(SpinnerComponent); comp = fixture.componentInstance; fixture.detectChanges(); }); it('Should Create a Spinner Component', () => { fixture.detectChanges(); var compiled = fixture.debugElement.nativeElement; expect(compiled).toBeTruthy(); }); it('Should not

Ng5 Karma Jasmine test renders component instead of result page

巧了我就是萌 提交于 2019-12-23 09:16:29
问题 Let's say i have a very simple 'create' unit test, kind that ng cli generates for you: describe('MyComponent', () => { let component: MyComponent; let fixture: ComponentFixture<MyComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [MyComponent], imports: [ HttpClientTestingModule, FormsModule, RouterTestingModule.withRoutes([{ path: 'home', redirectTo: '/' }]) ], providers: [SomeService1, SomeService2, { provide: SomeService3, useValue: {} }], schemas: [NO

Jasmine: How to mock MutationObserver?

天涯浪子 提交于 2019-12-23 07:17:07
问题 I have a angularjs component, HTML template <div id="panel" class="hide-div"> <div id="viewPort" class="hide-div"> ... </div> </div> JS var myController = function() { var ctrl=this; ctrl.$onchanges = function() { } var source = $("#viewport"); var target = $("#panel"); var observer = new MutationObserver(function() { target.toggleClass("hide-div", source.hasClass("hide-div")); }); observer.observe($("#viewport")[0], {attributes: true}); } var config = { controller: [myController],