Javascript Chrome扩展Jasmine测试、Chrome、onMessage请求方法未识别
因此,我编写了一个小的chrome扩展,在chrome中获取我的选择,并将其添加到弹出窗口中的一个小文本框中 对于Chrome扩展,我想用Jasmine编写一些小测试。但是,每当我尝试将我的消息Javascript Chrome扩展Jasmine测试、Chrome、onMessage请求方法未识别,javascript,google-chrome,testing,google-chrome-extension,jasmine,Javascript,Google Chrome,Testing,Google Chrome Extension,Jasmine,因此,我编写了一个小的chrome扩展,在chrome中获取我的选择,并将其添加到弹出窗口中的一个小文本框中 对于Chrome扩展,我想用Jasmine编写一些小测试。但是,每当我尝试将我的消息request.method测试为setrequest.method时,Jasmine总是返回 错误:预期未定义为“get\u sel\u chrome” 这似乎很小,但我就是找不到我做错了什么 这是我的档案: //Jasmine Main Specification File //Creating S
request.method
测试为setrequest.method
时,Jasmine总是返回
错误:预期未定义为“get\u sel\u chrome”
这似乎很小,但我就是找不到我做错了什么
这是我的档案:
//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(){
});
});
我的主JS文件:
//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
});
第二档
$(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;
});
});
}
此将请求。方法设置为获取选择铬,这可能不是您想要的
为了避免将来出现这种情况,请参见为什么要使用==
进行比较。你也应该明白这一点
此将请求。方法设置为获取选择铬,这可能不是您想要的
为了避免将来出现这种情况,请参见为什么要使用==
进行比较。也应该注意到这一点。可能是因为chrome.extension不推荐用于消息传递,使用chrome.runtime可能是因为chrome.extension不推荐用于消息传递,使用chrome.runtime
if (request.method = "get_sel_chrome"){