1.6.0 • Published 8 years ago

chrome-stub v1.6.0

Weekly downloads
16
License
ISC
Repository
github
Last release
8 years ago

chrome-stub

Chrome API mocking library.

npm install chrome-stub

Build Status Coverage Status

usage

In most cases you will want to set this as a global at the top of your test file, because chrome is a global in your extension code.

chrome = require('chrome-stub')

i18n

To use the I18n library, chrome-stub loads a default messages.json file that has only one string in it, 'test' If you pass a string that does not exist, you will receive a blank string back.

If you want to load a different messages.json file, for example the one you use in your chrome extension then use the method below in your test file.

_locales/ru/messages.json

{
	"test": {
		"message": "Тест"
	}
}

test.js

let path = require('path');

let config = path.resolve(process.cwd(), '_locales/ru/messages.json');

chrome.loadDefaults(config);
chrome.i18n.getMessage('test'); // Тест

All other APIs

All chrome APIs have been stubbed with sinon stub. You can define your own application-specific behavior of the stubs by following the sinon stub api. This allows you to define your behavior within your tests. For example:

// inside test
chrome.tabs.query.yields([{
  id:0,index:0,windowId:0,highlighted:true,
  active:true,pinned:false,url:'https://example.com',title:'example.com - Home',
  favIconUrl:'https://example.com/favicon.ico',status:'complete',width:800,height:600
}]);

// do something that causes your code to call chrome.tabs.query, e.g.:
getFirstTab(function(tab){
  // ...
  // your code's callback is called with the value provided to yields()
});

Originally forked from sethmcl/chrome-mock

1.6.0

8 years ago

1.5.0

9 years ago

1.4.0

9 years ago

1.3.2

10 years ago

1.3.1

10 years ago

1.3.0

10 years ago

1.2.0

11 years ago

1.1.0

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago