分离工具函数

This commit is contained in:
Harvey committed 2019-11-14 11:24:02 +08:00
1 parent 7a84c262da
commit 8ef582f714
22 files changed
+724 -687

No files matched your search

+11 -27
View File
@@ -1,4 +1,12 @@
var url = 'https://zhw2590582.github.io/assets-cdn/video/one-more-time-one-more-chance-480p.mp4';
describe('Constructor', function() {
afterEach(function() {
[...Artplayer.instances].forEach(art => {
art.destroy(true);
});
});
it('Constructor is a global variable', function() {
expect(Artplayer).to.be.an('function');
expect(Artplayer.instances).to.be.an('array');
@@ -6,35 +14,11 @@ describe('Constructor', function() {
});
it('Instance state', function() {
var sample1 = new Artplayer({ ...artBaseOption, container: '.sample1' });
var sample1 = new Artplayer({ container: '.sample1', url: url });
expect(sample1.id).to.equal(1);
var sample2 = new Artplayer({ ...artBaseOption, container: '.sample2' });
var sample2 = new Artplayer({ container: '.sample2', url: url });
expect(sample2.id).to.equal(2);
var sample3 = new Artplayer({ ...artBaseOption, container: '.sample3' });
var sample3 = new Artplayer({ container: '.sample3', url: url });
expect(sample3.id).to.equal(3);
});
it('Throw error when multiple instances on the same dom element', function() {
expect(function() {
new Artplayer({ ...artBaseOption, container: '.sample1' });
}).to.throw(/Cannot mount multiple instances on the same dom element/);
});
it('Throw error when container is not a dom element or selector', function() {
expect(function() {
new Artplayer(
Object.assign({}, artBaseOption, {
container: null,
}),
);
}).to.throw(/option.container require \'string\' or \'Element\' type/);
});
it('Destroy all instances', function() {
expect(Artplayer.instances.length).to.equal(3);
[...Artplayer.instances].forEach(art => {
art.destroy(true);
});
expect(Artplayer.instances.length).to.equal(0);
});
});
+47 -47
View File
@@ -1,49 +1,49 @@
<html>
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
<link href="../dist/artplayer.css" rel="stylesheet" />
<style>
.artplayer-app {
display: flex;
height: 300px;
border-bottom: 1px solid #999;
}
.artplayer-app > div {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
padding: 10px;
border-right: 1px solid #999;
}
</style>
</head>
<body>
<div class="artplayer-app">
<div class="sample1">sample1</div>
<div class="sample2">sample2</div>
<div class="sample3">sample3</div>
</div>
<div id="mocha"></div>
<script src="https://unpkg.com/chai/chai.js"></script>
<script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>
<script>
window.mocha.setup('bdd');
window.expect = window.chai.expect;
window.artBaseOption = {
url: 'https://zhw2590582.github.io/assets-cdn/video/one-more-time-one-more-chance-480p.mp4',
autoSize: true,
};
</script>
<!-- <script src="../docs/uncompiled/artplayer.js"></script> -->
<script src="../dist/artplayer.js"></script>
<script src="./constructor.test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>
<head>
<meta charset="utf-8" />
<title>Mocha Tests</title>
<link href="https://unpkg.com/mocha@5.2.0/mocha.css" rel="stylesheet" />
<link href="../dist/artplayer.css" rel="stylesheet" />
<style>
.artplayer-app {
display: flex;
height: 300px;
border-bottom: 1px solid #999;
}
.artplayer-app>div {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
padding: 10px;
border-right: 1px solid #999;
}
</style>
</head>
<body>
<div class="artplayer-app">
<div class="sample1">sample1</div>
<div class="sample2">sample2</div>
<div class="sample3">sample3</div>
</div>
<div id="mocha"></div>
<script src="https://unpkg.com/chai/chai.js"></script>
<script src="https://unpkg.com/mocha@5.2.0/mocha.js"></script>
<script>
window.mocha.setup('bdd');
window.expect = window.chai.expect;
</script>
<script src="../docs/uncompiled/artplayer.js"></script>
<!-- <script src="../dist/artplayer.js"></script> -->
<script src="./constructor.test.js"></script>
<script src="./option.test.js"></script>
<script>
mocha.checkLeaks();
mocha.run();
</script>
</body>
</html>
+32
View File
@@ -0,0 +1,32 @@
var url = 'https://zhw2590582.github.io/assets-cdn/video/one-more-time-one-more-chance-480p.mp4';
describe('Option', function() {
afterEach(function() {
[...Artplayer.instances].forEach(art => {
art.destroy(true);
});
});
it('Throw error when multiple instances on the same dom element', function() {
expect(function() {
new Artplayer({ container: '.sample1', url: url });
new Artplayer({ container: '.sample1', url: url });
}).to.throw(/Cannot mount multiple instances on the same dom element/);
});
it('Throw error when container is not a dom element or selector', function() {
expect(function() {
new Artplayer({
container: null,
url: url,
});
}).to.throw(/option.container require \'string\' or \'Element\' type/);
});
it('The url can return a promise', function() {
new Artplayer({
container: '.sample1',
url: () => Promise.resolve(url),
});
});
});