Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] check destroyed before we destroy plugin
- Loading branch information
1 parent
c21f872
commit af4c40f
Showing
8 changed files
with
715 additions
and
686 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import Plugin from 'dispatcher/plugin'; | ||
import Chimee from 'index'; | ||
|
||
describe("plugin's error", () => { | ||
let dispatcher; | ||
let player; | ||
let error; | ||
|
||
beforeEach(() => { | ||
player = new Chimee({ | ||
// 播放地址 | ||
src: 'http://cdn.toxicjohann.com/lostStar.mp4', | ||
// 直播:live 点播:vod | ||
isLive: false, | ||
// 编解码容器 | ||
box: 'native', | ||
// dom容器 | ||
wrapper: 'body', | ||
plugin: [], | ||
events: {}, | ||
}); | ||
|
||
dispatcher = player.__dispatcher; | ||
|
||
error = new Error('i am an error'); | ||
}); | ||
|
||
afterEach(() => { | ||
player.destroy(); | ||
dispatcher = null; | ||
}); | ||
|
||
test('beforeCreate', () => { | ||
expect(() => new Plugin({ | ||
id: 'err', | ||
beforeCreate() { | ||
throw error; | ||
}, | ||
}, dispatcher)).toThrow(error.message); | ||
}); | ||
|
||
test('create', () => { | ||
expect(() => new Plugin({ | ||
id: 'err', | ||
create() { | ||
throw error; | ||
}, | ||
}, dispatcher)).toThrow(error.message); | ||
}); | ||
|
||
test('init', () => { | ||
const plugin = new Plugin({ | ||
id: 'err', | ||
init() { | ||
throw error; | ||
}, | ||
}, dispatcher); | ||
expect(() => plugin.__init({})).toThrow(error.message); | ||
}); | ||
|
||
test('inited', () => { | ||
const plugin = new Plugin({ | ||
id: 'err', | ||
inited() { | ||
throw error; | ||
}, | ||
}, dispatcher); | ||
expect(() => plugin.__inited({})).toThrow(error.message); | ||
}); | ||
|
||
test('inited with promise', async () => { | ||
const plugin = new Plugin({ | ||
id: 'err', | ||
inited() { | ||
return new Promise(() => { throw error; }); | ||
}, | ||
}, dispatcher); | ||
let catcherr = false; | ||
try { | ||
await plugin.__inited({}); | ||
} catch (err) { | ||
catcherr = true; | ||
expect(err).toBe(error); | ||
} | ||
expect(catcherr).toBe(true); | ||
}); | ||
|
||
test('inited with reject', async () => { | ||
const plugin = new Plugin({ | ||
id: 'err', | ||
inited() { | ||
return Promise.reject(); | ||
}, | ||
}, dispatcher); | ||
expect(plugin.__inited({})).rejects.toBe(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.