|
1 | 1 | import * as Check from '../../src/utils/check' |
2 | 2 | import { expect } from 'chai' |
3 | 3 |
|
4 | | -describe('Utils function', () => { |
| 4 | +describe('Utils function test', () => { |
5 | 5 |
|
6 | | - it('pages should return false and print warning', done => { |
7 | | - const result = Check.pages(['123']) |
8 | | - expect(result).to.eq(false) |
9 | | - done() |
| 6 | + let _warn: (msg?: any, ...p: any[]) => void |
| 7 | + before(() => { |
| 8 | + // hack warn func, utils function maybe use it |
| 9 | + _warn = global.console.warn |
| 10 | + global.console.warn = () => {} |
10 | 11 | }) |
11 | 12 |
|
12 | | - it('link should return false and print warning', done => { |
13 | | - const result = Check.scripts(['123']) |
14 | | - expect(result).to.eq(false) |
15 | | - done() |
| 13 | + after(() => { |
| 14 | + global.console.warn = _warn |
| 15 | + }) |
| 16 | + |
| 17 | + it('should return boolean and identify page url', () => { |
| 18 | + expect(Check.pages(['http://baidu.com'])).to.be.eq(true) |
| 19 | + expect(Check.pages(['https://baidu.com'])).to.be.eq(true) |
| 20 | + expect(Check.pages(['//baidu.com'])).to.be.eq(true) |
| 21 | + expect(Check.pages(['baidu.com'])).to.be.eq(false) |
| 22 | + expect(Check.pages(['www.baidu.com'])).to.be.eq(false) |
| 23 | + expect(Check.pages([''])).to.be.eq(false) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should return boolean and identify script url', () => { |
| 27 | + expect(Check.scripts(['http://npm.some.js'])).to.be.eq(true) |
| 28 | + expect(Check.scripts(['https://npm.some.js'])).to.be.eq(true) |
| 29 | + expect(Check.scripts(['//npm.some.js'])).to.be.eq(true) |
| 30 | + expect(Check.scripts(['https://npm.some.css'])).to.be.eq(false) |
| 31 | + expect(Check.scripts(['https://npm.some.com/'])).to.be.eq(false) |
| 32 | + expect(Check.scripts(['hello.npm.some.com'])).to.be.eq(false) |
| 33 | + expect(Check.scripts([''])).to.be.eq(false) |
| 34 | + }) |
| 35 | + |
| 36 | + it('should return boolean and identify all options', () => { |
16 | 37 | }) |
17 | 38 |
|
18 | 39 | }) |
|
0 commit comments