Skip to content

Instantly share code, notes, and snippets.

@danilobatistaqueiroz
Last active February 14, 2018 17:27
Show Gist options
  • Save danilobatistaqueiroz/f60cd460cf13eb4389ea633b8102ddf4 to your computer and use it in GitHub Desktop.
Save danilobatistaqueiroz/f60cd460cf13eb4389ea633b8102ddf4 to your computer and use it in GitHub Desktop.
jasmine protractor karma grunt bower yarn gulp webdriver selenium phantomjs

Jasmine

Jasmine is a behavior-driven development framework for testing JavaScript code.
It does not depend on any other JavaScript frameworks.

Specs
Specs are defined by calling the global Jasmine function it, which, like describe takes a string and a function.

describe("A suite is just a function", function() {
  var a;

  it("and so is a spec", function() {
    a = true;

    expect(a).toBe(true);
  });
});

Setup and Teardown
To help a test suite DRY up any duplicated setup and teardown code, Jasmine provides the global beforeEach, afterEach, beforeAll, and afterAll functions.

describe("A spec using beforeEach and afterEach", function() {
  var foo = 0;

  beforeEach(function() {
    foo += 1;
  });

  afterEach(function() {
    foo = 0;
  });

  it("is just a function, so it can contain any code", function() {
    expect(foo).toEqual(1);
  });

  it("can have more than one expectation", function() {
    expect(foo).toEqual(1);
    expect(true).toEqual(true);
  });
});

Spies
Jasmine has test double functions called spies.
A spy can stub any function and tracks calls to it and all arguments.


Karma

Karma is a test runner built by angular's team

Karma watches all the files, specified within the configuration file.
Whenever any file changes,
it triggers the test run by sending a signal to the testing server to inform all of the captured browsers to run the test code again.
Each browser then loads the source files inside an IFrame, executes the tests and reports the results back to the server.

The server collects the results from all of the captured browsers and presents them to the developer.


Protractor

Protractor is an end-to-end test framework for Angular and AngularJS applications.
Protractor runs tests against your application running in a real browser, interacting with it as a user would.

Test Like a User
Protractor is built on top of WebDriverJS, which uses native events and browser-specific drivers to interact with your application as a user would.

For Angular Apps
Protractor supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any setup effort on your part.

Automatic Waiting
You no longer need to add waits and sleeps to your test.
Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment