jasmine

Definitions of identifiers conflict with those in another file

帅比萌擦擦* 提交于 2019-12-12 13:11:07
问题 I'm updating an old component from Typescript 6 to 8. I've updated the Jasmine dependencies in the package.json , but now I'm getting an error: "Definitions of the following identifiers conflict with those in another file: ImplementationCallback, ExpectedRecursive, Expected, SpyObjMethodNames, CustomEqualityTester, CustomMatcherFactory, ExpectationFailed, SpecFunction, SpyObj, jasmine". The two conflicting files are the following: @types/jasmine/index.d.ts @types/jasmine/ts3.1/index.d.ts I've

Testing model binding in Backbone JS with Jasmine

喜欢而已 提交于 2019-12-12 13:03:34
问题 I have a view that contains a model. The view listens for an event from the model and will perform an action once the event is triggered. Below is my code window.Category = Backbone.Model.extend({}) window.notesDialog = Backbone.View.extend({ initialize: function() { this.model.bind("notesFetched", this.showNotes, this); }, showNotes: function(notes) { //do stuffs here } }) I want to test this using Jasmine and below is my test (which doesn't work) it("should show notes", function() { var

How to mock $scope.variables in jasmine

本秂侑毒 提交于 2019-12-12 13:01:07
问题 I have the following test case CompanyCtrlSpec.js describe('ViewCompanyCtrl', function () { var $rootScope, scope, $controller , $q ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function() { return $controller('ViewCompanyCtrl', { $scope: scope, company : {} }); }; })); it('the company type should be equal to an object', function () { var controller = new createController(); //some assertion })

What is document.body in Jasmine tests?

橙三吉。 提交于 2019-12-12 12:16:56
问题 Where does document.querySelector('body') point to in Jasmine tests? Is it blank, or how does it look like? Is new page is loaded in "default" state for each test case or it is shared accross tests? 回答1: The document.body is that of the test runner HTML file which has each of your source and test files loaded into it. It is globally available and constantly there, so is the same and shared across all tests. 来源: https://stackoverflow.com/questions/39139570/what-is-document-body-in-jasmine

Error debugging protractor with node 8 async/await and angular 6

梦想的初衷 提交于 2019-12-12 12:03:46
问题 I can not get the protractor debugger to work with node 8 async/await and Angular 6. Going back to node 7 in the old way with elementExplorer , browser.pause() and browser.debugger() is not an option. Also because in the future, the control flow is being removed from Selenium and I keep reading that it's a better debugging experience using node 8 async/await instead of control flow . I am using angular 6.0.3, angular CLI 6.0.5, node 8.11.2 & chrome 71.0.3578.98. I reproduce the problem by

jasmine mock-ajax with JSON

落花浮王杯 提交于 2019-12-12 12:00:18
问题 I have tried to mock/stub my ajax call, but it looks like it only works with text. When I tried to set response with object then my done callback is not called: jasmine.Ajax.stubRequest('/some_url/1').andReturn({ //"responseText": response , "response": response, "status": 200 }); , but when I set responseText with object then it is called, but the responseJSON is not set, when debug response in FF responseJSON undefined status 200 statusText "success" Am I doing something wrong or it is an

Testing if a Jasmine Test Fails

允我心安 提交于 2019-12-12 11:42:29
问题 I'm trying to write a plugin for Jasmine that allows you to return a promise from a spec and will pass or fail that spec depending on whether or not the promise is fulfilled or rejected. Of course, I want to write tests to make sure that my plugin works correctly, and to be thorough, I need to make sure that tests fail when the promise is rejected... so how do I make a test pass when I need to make sure that a test "successfully fails"? 回答1: After a conversation with the developers who work

Mocking ngResource in Angular unit tests

扶醉桌前 提交于 2019-12-12 10:56:33
问题 I have an ngResourceMockFactory which looks like this: (function() { 'use strict'; angular.module('app') .factory('NgResourceMock', ngResourceMockFactory) ; ngResourceMockFactory.$inject = []; function ngResourceMockFactory() { function NgResourceMock() { var context = this; context.$promise.then = function() { context.prototype.$promise.then.apply(context, arguments); }; context.$promise.finally = function() { context.prototype.$promise.finally.apply(context, arguments); }; } NgResourceMock

How to mock AngularJS $resource with $promise.then in jasmine specs

故事扮演 提交于 2019-12-12 10:46:40
问题 I use $resource to set up some API calls, and while testing I have adopted the general approach of injecting $q and then doing mockMyService.doSomethingAsync.andReturnValue($q.when(successResponse)) This has been working out pretty well, however, I have a method that looks like the following: # MyService MyService.doSomethingAsync(params).$promise.then -> $scope.isLoading = false # MyService Spec mockMyService = doSomethingAsync: jasmine.createSpy('doSomethingAsync') it 'calls service

Angular Testing, dynamically change ActivatedRoute params for different test cases

孤街醉人 提交于 2019-12-12 10:39:28
问题 Component: @Component({ selector: 'app-test', templateUrl: './test.component.html' }) export class TestComponent implements OnInit { useCase: string; constructor( private route: ActivatedRoute, ) {} ngOnInit() { this.route.queryParams.subscribe(p => { if (p) { this.useCase = p.u; } }); } } Test Spec describe('TestComponent', () => { let component: TestComponent; let fixture: ComponentFixture<TestComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ imports: [ AppModule ],