jasmine

Angular testing how to prevent ngOnInit call to test a method directly

瘦欲@ 提交于 2019-11-30 11:27:27
问题 Context I have a component. Inside of it, the ngOnInit function calls another function of component to retrieve user List. I want to make two series of tets: First test the ngOnInit is triggered properly and populate the user list In a second time I want to test my refresh function which also call getUserList() The first test, with ngOnInit trigger, when I call fixture.detectChanges() works properly. Problem My problem is when testing the refresh function: as soon as I call fixture

How can I get my jasmine tests fixtures to load before the javascript considers the document to be “ready”?

两盒软妹~` 提交于 2019-11-30 11:27:21
I am fairly certain that the issue is that the jquery bindings set to run on $(document).ready do not have the fixture html available to them. So when my events occur that are intended to make a change to the DOM via a jquery function, nothing happens, and my tests fail. I saw a "solution" to this problem here , but that solution which did work for me, required changing my working jquery function to bind with the .live method instead of the .click method. I have two issue with this. First I do not want to have to change my working code so that the tests will pass properly. The testing

Unit Test with Mongoose

雨燕双飞 提交于 2019-11-30 11:18:41
I'm new to Node.js, Mongoose, and testing in this environment. I have the following schema declared in a separate file. Issue = mongoose.model("Issue", { identifier: String, date: String, url: String, name: String, thumbnailURL: String }); Then I have this method which simply returns all of the Issue instances in the MongoDB collection. function issues(request, response) { response.setHeader('Content-Type', 'text/json'); Issue.find().sort('date').exec(function(error, items) { if (error) { response.send(403, {"status": "error", "error:": exception}); } else { response.send(200, {"issues": items

How to test John papa vm.model unit testing with jasmine?

允我心安 提交于 2019-11-30 11:17:19
I use John papa angular style guide my controller looks like: following the style John papa style controller style guide : function testController() { var vm = this; vm.model = { name: "controllerAs vm test" }; } My testing code looks like: describe('Controller: testController', function () { beforeEach(module('myApp')); var testController; beforeEach(inject(function ($controller) { scope = {}; testController = $controller('testController', { }); })); it('should have vm.model defined and testController.vm.model is equal to controllerAs vm test', function () { expect(testController.vm)

What do jasmine runs and waitsFor actually do?

三世轮回 提交于 2019-11-30 11:07:52
I use jasmine runs and wait to test asynchronous operations. Everything works fine but I'm not quite sure what goes on behind the scenes. The jasmine documentation states the following example to which I added three log statement. describe("Asynchronous specs", function() { var value, flag; it("should support async execution of test preparation and exepectations", function() { runs(function() { flag = false; value = 0; setTimeout(function() { flag = true; }, 500); }); waitsFor(function() { value++; if(flag) { console.log("A"); } return flag; }, "The Value should be incremented", 750); console

Expected [ ] to be [ ] Jasmine, how to check empty array

瘦欲@ 提交于 2019-11-30 11:03:24
Getting error while trying to check for empty array. I tried using: Case 1: By initializing as an array expect(fixture.componentInstance.dataSource).toBe([]); Case 2: By initializing as an array let expectedAry = new Array; expect(fixture.componentInstance.dataSource).toBe(expectedAry); Both the case have the same error: Expected [ ] to be [ ]. Arrays can also be checked by their length, the following works fine expect(fixture.componentInstance.dataSource.length).toEqual(0); 0 length is an option, but not sure if that is the right way to check whether an array is empty. Do we have a better

Is it possible to use Jasmine's toHaveBeenCalledWith matcher with a regular expression?

爱⌒轻易说出口 提交于 2019-11-30 10:40:50
I have reviewed Jasmine's documentation of the toHaveBeenCalledWith matcher in order to understand whether it's possible to pass in a regular expression for an argument, if that argument is expected to be a string. Unfortunately, this is unsupported functionality. There's also an issue open on github requesting this functionality. I've dug a bit into the codebase, and I see how it might be possible to implement this inside the existing matcher . I think it would be more appropriate to implement it as a separate matcher though, so that the abstraction is captured individually. In the meantime,

Jenkins could not generate HTML Report folder on slave-machine

谁都会走 提交于 2019-11-30 09:47:43
问题 I am trying to generate HTML reports(Protractor Test) through Jenkins but it says "ERROR: Specified HTML directory 'x/y/z/Reports' does not exist". but when i run on the slave reports were generated. What do i need to do on the Jenkins Configuration, please help on this. *Path is correct but it could not generate "Reports" folder on the slave. I am using- "protractor-html-screenshot-reporter" 回答1: You need specify the path like "\x\y\z\Reports\", and make sure those folders is existing on

undefined|0|ReferenceError: Strict mode forbids implicit creation of global property 'csrf_token'

跟風遠走 提交于 2019-11-30 08:56:38
问题 So, this was quite an interesting problem I have been running into. I am currently building a backbone.js - Rails app. Generally just building this for learning purposes. I am (like any good rails dev) doing my best at TDD/BDD and I ran into a problem with capybara. I have an integration spec that merely tests root_path works (Backbone history starts, displays initial information, etc...). require 'spec_helper' describe "RentalProperties", js: true do describe "GET /" do it "should show a

Making real requests to HTTP server in AngularJS unit/integration tests

柔情痞子 提交于 2019-11-30 08:46:20
问题 Making a request that wasn't mocked with $httpBackend.when in Angular 1.x unit/integration test results in an error: Error: Unexpected request: GET /real-request Is it possible to make real HTTP requests with ngMock and Karma+Jasmine test rig? What is a good practice to do that? 回答1: AngularJS is opinionated framework, and its opinion on HTTP requests in unit tests is that all of them should be mocked. It is not advisable to do real HTTP requests in unit tests for two reasons. Unit tests are