[英]Sinon.spy() & jest.spyOn - TypeError: Attempted to wrap undefined property getTableData as function
[英]TypeError: 'undefined' is not a function (evaluating 'sinon.spy()')
我正在嘗試使用sinon.js來測試骨干應用程序。 但不幸的是我因為錯誤而無法使用間諜方法:
TypeError: 'undefined' is not a function (evaluating 'sinon.spy()')
以下是重現錯誤的步驟:
cd test && bower install sinon
<script src="bower_components/sinon/lib/sinon.js"></script>
在test / spec / test.js中創建間諜:
describe('Give it some context', function () { describe('maybe a bit more context here', function () { it('should run here few assertions', function () { var spy = sinon.spy(); spy.should.be.ok; }); }); });
用grunt: grunt test
運行grunt test
測試將失敗並顯示錯誤。
誰能幫忙找出問題所在?
我將只留下sinon
方便忘記加載的文件列表,如果它作為<script>
或require.js
(作為AMD模塊)加載 - 基本上除了node.js
之外的任何東西:
"sinon/lib/sinon.js",
"sinon/lib/sinon/spy.js",
"sinon/lib/sinon/call.js",
"sinon/lib/sinon/behavior.js",
"sinon/lib/sinon/stub.js",
"sinon/lib/sinon/mock.js",
"sinon/lib/sinon/collection.js",
"sinon/lib/sinon/assert.js",
"sinon/lib/sinon/sandbox.js",
"sinon/lib/sinon/test.js",
"sinon/lib/sinon/test_case.js",
"sinon/lib/sinon/match.js"
隨意跳過這些,但希望sinon以奇怪的方式失敗。
事實證明,應該通過包含lib/sinon
文件夾中的腳本手動添加間諜,存根等功能。 安裝部分提到了這一事實。 並且由於僅在Node.js環境中的核心sinon.js文件的代碼,它是自動完成的。
與其他答案不同,我沒有通過包含每個單獨的源文件手動安裝simon。 相反,我遵循了如何在瀏覽器中使用Bower安裝Sinon.JS的建議。
bower install http://sinonjs.org/releases/sinon-1.17.6.js
然后
bower list -p
'sinon-1.17.6': 'bower_components/sinon-1.17.6/index.js'
和
<script src="bower_components/sinon-1.17.6/index.js"></script>
為我工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.