ysz-test-sdk
Version:
* 1 npm install --save-dev jest ts-jest @types/jest * 2 Modify your project's package.json ``` "jest": { "transform": { "^.+\\.tsx?$": "ts-jest" }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", "moduleFileExtensions
43 lines (40 loc) • 1.02 kB
text/typescript
import WebSDK, { WebSDKBOM } from '../src'
it('test YY', () => {
window.YY = {
sayHello(name) {
return true
}
}
expect(WebSDK('sayHello', 'youxiu')).toBe(true)
delete window.YY
})
WebSDKBOM.keysConfig({
code: 'key'
})
describe('test moschat', () => {
test('moschat sayHello,返回undefined', () => {
expect(WebSDK('setName', 'youxiu')).not
window.moschat = {
setTitle(name) {
return true
},
getVersion() {
return '1.2.1'
}
}
})
describe('moschat 重写catchError方法,返回false', () => {
test('moschat catchError方法', () => {
// 重写错误方法
WebSDKBOM.catchError = function(error) {
return false
}
expect(WebSDK('setName', 'youxiu')).toBe(false)
})
test('moschat getVersion方法', () => {
expect(WebSDK('getVersion')).toBe('1.2.1')
// delete window.moschat
console.log('-------window-', window.moschat)
})
})
})