Skip to content

Commit 91d1a34

Browse files
鲁飞鲁飞
authored andcommitted
feat: unit testing
1 parent fd9d8b4 commit 91d1a34

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"types": "dist/type/index.d.ts",
88
"scripts": {
99
"build": "rm -fr dist & rollup -c",
10-
"declaration": "tsc --declaration --declarationDir dist/type ./src/index.ts --emitDeclarationOnly",
11-
"test": "echo \"Error: no test specified\" && exit 1"
10+
"test": "mocha test/",
11+
"declaration": "tsc --declaration --declarationDir dist/type ./src/index.ts --emitDeclarationOnly"
1212
},
1313
"browserslist": [
1414
"android >= 5",
@@ -22,6 +22,8 @@
2222
"license": "MIT",
2323
"devDependencies": {
2424
"@rollup/plugin-typescript": "^4.1.2",
25+
"expect.js": "^0.3.1",
26+
"mocha": "^8.0.1",
2527
"rollup": "^2.15.0",
2628
"rollup-plugin-terser": "^6.1.0",
2729
"tslib": "^2.0.0",

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
file: 'dist/cox.es.js'
1919
},
2020
{
21-
format: 'iife',
21+
format: 'umd',
2222
sourcemap: true,
2323
name: 'cox',
2424
file: 'dist/cox.min.js'

test/collide.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const expect = require('expect.js')
2+
const {collide, Polygon, Circle} = require('../dist/cox.min')
3+
4+
describe('collide', () => {
5+
let polygon, circle, square
6+
7+
before(() => {
8+
polygon = new Polygon({
9+
x: 380,
10+
y: 504,
11+
vertices: [-60, -60, -120, 0, -60, 60, 60, 60, 120, 0, 60, -60]
12+
})
13+
14+
circle = new Circle({
15+
x: 518,
16+
y: 656,
17+
r: 50
18+
})
19+
20+
square = new Polygon({
21+
x: 461,
22+
y: 575,
23+
vertices: [-50, -50, 50, -50, 50, 50, -50, 50]
24+
})
25+
})
26+
27+
it('正方形与圆碰撞', () => {
28+
expect(collide(square, circle)).to.be.ok()
29+
})
30+
31+
it('多边形与圆不碰撞', () => {
32+
expect(collide(polygon, circle)).to.not.be.ok()
33+
})
34+
35+
it('多边形与正方形碰撞', () => {
36+
expect(collide(polygon, square)).to.be.ok()
37+
})
38+
})

0 commit comments

Comments
 (0)