Jasmine Spies.and.stub method

For the term, you can look at wikipedia : http://en.wikipedia.org/wiki/Test_stub In a nutshell it’s a “fake” object that you can control that replaces a “real” object in your code. For the function, what I understand is that and.stub() removes the effect of and.callThrough() on a spy. When you call and.callThrough, the spy acts as a … Read more

Jasmine test a promise.then function

the jasmine ‘it’ method takes a done parameter that you can call for async testing it(‘Should be async’, function(done) { someAsyncFunction().then(function(result) { expect(result).toBe(true); done(); }); }); Feel free to go as deep as you want, just be sure to call done when EVERYTHING is finished. Jasmine’s default timeout is 5 seconds per test, so if … Read more

How to mock Angular 4.3 httpClient an error response in testing

The expectOne method in HttpTestingController class returns a TestRequest object. This TestRequest class has a flush method which can be used to deliver both successful and unsuccessful responses. We can resolve the request by returning a body along with some additional response headers (if any). Relevant info can be found here. Now, coming back to … Read more

Injecting dependent services when unit testing AngularJS services

Actually in AngularJS Dependency Injection uses the ‘last wins’ rule. So you can define your service in your test just after including your module and dependencies, and then when service A that you’re testing will request service B using DI, AngularJS will give mocked version of service B. This is often is done by defining … Read more

How to run Jasmine tests on Node.js from command line

This should get you going quickly: install Node.js (obviously). Next install Jasmine. Open a command prompt and run: npm install -g jasmine Next, cd to any directory and set up an example ‘project’: jasmine init jasmine examples Now run your unit tests: jasmine If your jasmine.json file is somewhere else besides spec/support/jasmine.json, simply run: jasmine … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)