Skip to content

RyanV/jasmine-fake-window

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jasmine-fake-window

jasmine-fake-window is an extension for Jasmine JavaScript Testing Framework:

  • minimally obtrusive utility for handling window mocking in jasmine
  • currently only handles window.location

Installation

download jasmine-fake-window.js from here and include it in your Jasmine's test runner file (or add it to jasmine.yml file if you're using Ruby with jasmine-gem);

Usage

// source file
MyObjectNamespace = {
  window: window,
  goToUrl: function(url) {
    MyObjectNamespace.window.location.href = url
  }
}
// MyObjectNamespace spec
describe("MyObjectNamespace.window.location.href", function() {
  beforeEach(function() {
    MyObjectNamespace.window = jasmine.fakeWindow
  });

  it('does not change the page location', function() {
    MyObject.window.location.href = 'http://www.fake.com';
    // this spec would never run otherwise, because it would navigate
    // to another page.
    expect(MyObject.window.location.href).toEqual('http://www.fake.com');
    MyObject.goToUrl('http://www.google.com');
    // this spec wouldn't ever run either
    expect(MyObject.window.location.href).toEqual('http://www.google.com');
  });
});

Running Specs

run grunt from the command line to lint and run specs

Building distrubution

run grunt preprocess

TODO

  • add navigator functionality
  • DRY up code
  • add init function to automatically set before and after blocks to reset the location or tie fake window in jasmine.Env

About

fake window object for running jasmine specs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published