Is there a good way to do this? I\'m writing an extension that interacts with a website as a content script and saves data using localstorage. Are there any tools, framework
While sinon.js seems to work great, you can also just use plain Jasmine and mock the Chrome callbacks you need. Example:
Mock
chrome = {
runtime: {
onMessage : {
addListener : function() {}
}
}
}
Test
describe("JSGuardian", function() {
describe("BlockCache", function() {
beforeEach(function() {
this.blockCache = new BlockCache();
});
it("should recognize added urls", function() {
this.blockCache.add("http://some.url");
expect(this.blockCache.allow("http://some.url")).toBe(false);
});
} // ... etc
Just modify the default SpecRunner.html to run your code.