|
| 1 | +import Vue from 'vue-native/index' |
| 2 | + |
| 3 | +describe('Initialization', () => { |
| 4 | + function noop () {} |
| 5 | + |
| 6 | + let asserted |
| 7 | + |
| 8 | + function createCompareFn (spy) { |
| 9 | + const hasWarned = msg => { |
| 10 | + var count = spy.calls.count() |
| 11 | + var args |
| 12 | + while (count--) { |
| 13 | + args = spy.calls.argsFor(count) |
| 14 | + if (args.some(containsMsg)) { |
| 15 | + return true |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + function containsMsg (arg) { |
| 20 | + return arg.toString().indexOf(msg) > -1 |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + return { |
| 25 | + compare: msg => { |
| 26 | + asserted = asserted.concat(msg) |
| 27 | + var warned = Array.isArray(msg) |
| 28 | + ? msg.some(hasWarned) |
| 29 | + : hasWarned(msg) |
| 30 | + return { |
| 31 | + pass: warned, |
| 32 | + message: warned |
| 33 | + ? 'Expected message "' + msg + '" not to have been warned' |
| 34 | + : 'Expected message "' + msg + '" to have been warned' |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + // define custom matcher for warnings |
| 41 | + beforeEach(() => { |
| 42 | + asserted = [] |
| 43 | + spyOn(console, 'warn') |
| 44 | + spyOn(console, 'error') |
| 45 | + jasmine.addMatchers({ |
| 46 | + toHaveBeenWarned: () => createCompareFn(console.error), |
| 47 | + toHaveBeenTipped: () => createCompareFn(console.warn) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + afterEach(done => { |
| 52 | + const warned = msg => asserted.some(assertedMsg => msg.toString().indexOf(assertedMsg) > -1) |
| 53 | + let count = console.error.calls.count() |
| 54 | + let args |
| 55 | + while (count--) { |
| 56 | + args = console.error.calls.argsFor(count) |
| 57 | + if (!warned(args[0])) { |
| 58 | + done.fail(`Unexpected console.error message: ${args[0]}`) |
| 59 | + return |
| 60 | + } |
| 61 | + } |
| 62 | + done() |
| 63 | + }) |
| 64 | + |
| 65 | + it('without new', () => { |
| 66 | + try { Vue() } catch (e) {} |
| 67 | + expect('Vue is a constructor and should be called with the `new` keyword').toHaveBeenWarned() |
| 68 | + }) |
| 69 | + |
| 70 | + it('with new', () => { |
| 71 | + expect(new Vue() instanceof Vue).toBe(true) |
| 72 | + }) |
| 73 | +}) |
0 commit comments