So I've written a small chrome extension that gets my selection in chrome and adds it to a small textbox in a popup window.
For that Chrome Extension I want to write some small tests using Jasmine. However, whenever I try to test my Message request.method to be a set request.method, Jasmine always returns Error: Expected undefined to be 'get_sel_chrome. This might seem very minor but I just cant find the thing I am doing wrong.
Here are my Files:
//Jasmine Main Specification File
//Creating Suite
describe("Lacy-R Functionality Requirement Min Tests: ", function(){
//telling Jasmine to make sure that these are setup before each tests
beforeEach(function(){
chrome = {
extension: {
onMessage: {
addListener: function(request, sender, sendResponse){}
}
}
}
});
it('Check if Jasmine is loading. Just a small basic Jasmine test', function(){
expect(1).toEqual(1);
});
it('Checks if the request method is get_sel_chrome' , function(){
expect(chrome.extension.onMessage.addListener(function(request, sender, sendResponse){request.method})).toBe("undefined");
});
it('Using Chrome API functions' , function(){
});
});
My main JS file:
//stuff chrome does
chrome.extension.onMessage.addListener(function(request, sender, sendResponse){
if (request.method = "get_sel_chrome"){
sendResponse({data: window.getSelection().toString()});
}
else{
sendResponse({});} //empty response
});
Second File
$(function(){
$('#btn_run').click(function(){get_Info();});
});
function get_Info() {
chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT},
function(tab) {
chrome.tabs.sendMessage(tab[0].id, {method: "get_sel_chrome"},
function(response){
var text = document.getElementById('text');
text.innerHTML = response.data;
});
});
}
Aucun commentaire:
Enregistrer un commentaire