How to reuse beforeEach/afterEach in Jasmine JS?

I think this is partially examined in this blog post and also answered here but i’m adding an adapted answer for your example: Reusable code: function sharedSetup(startPage) { beforeEach(function() { login_as_admin(); browser().navigateTo(startPage); }); afterEach(function() { logout(); }); }; How to use it: describe(‘Services Page’, function() { sharedSetup(‘/services’); it(‘Some test for services page’, function() {}); }); … Read more

jasmine parameterized unit test

Based on piotrek’s answer and the article Parameterized testing in Javascript, you could also use the following approach which uses ES6 syntax: [ [‘abc’, 3], [‘ab’, 2], [”, 0], ].forEach(([string, expectedLength]) => { it(`should return length ${expectedLength} for string “${string}”`, () => { expect(string.length).toBe(expectedLength); }); }); I have tested it with the Jest test framework, … Read more

Jasmine test for object properties

It’s built in now! describe(“jasmine.objectContaining”, function() { var foo; beforeEach(function() { foo = { a: 1, b: 2, bar: “baz” }; }); it(“matches objects with the expect key/value pairs”, function() { expect(foo).toEqual(jasmine.objectContaining({ bar: “baz” })); expect(foo).not.toEqual(jasmine.objectContaining({ c: 37 })); }); }); Alternatively, you could use external checks like _.has (which wraps myObject.hasOwnProperty(prop)): var _ = … Read more

Testing directives that require controllers

I can think of two approaches: 1) Use both directives Let’s assume we have the following directives: app.directive(‘foo’, function() { return { restrict: ‘E’, controller: function($scope) { this.add = function(x, y) { return x + y; } } }; }); app.directive(‘bar’, function() { return { restrict: ‘E’, require: ‘^foo’, link: function(scope, element, attrs, foo) { … Read more

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