|
|
@@ -146,7 +146,7 @@ describe('Options props', () => {
|
|
|
})
|
|
|
|
|
|
describe('assertions', () => {
|
|
|
- function makeInstance (value, type, validator, required) {
|
|
|
+ function makeInstance (value, type, validator?, required?) {
|
|
|
return new Vue({
|
|
|
template: '<test :test="val"></test>',
|
|
|
data: {
|
|
|
@@ -169,56 +169,56 @@ describe('Options props', () => {
|
|
|
|
|
|
it('string', () => {
|
|
|
makeInstance('hello', String)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(123, String)
|
|
|
expect('Expected String with value "123", got Number with value 123').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('number', () => {
|
|
|
makeInstance(123, Number)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance('123', Number)
|
|
|
expect('Expected Number with value 123, got String with value "123"').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('number & boolean', () => {
|
|
|
makeInstance(123, Number)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(false, Number)
|
|
|
expect('Expected Number, got Boolean with value false').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('string & boolean', () => {
|
|
|
makeInstance('hello', String)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(true, String)
|
|
|
expect('Expected String, got Boolean with value true').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('boolean', () => {
|
|
|
makeInstance(true, Boolean)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance('123', Boolean)
|
|
|
expect('Expected Boolean, got String with value "123"').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('function', () => {
|
|
|
makeInstance(() => {}, Function)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(123, Function)
|
|
|
expect('Expected Function, got Number with value 123').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('object', () => {
|
|
|
makeInstance({}, Object)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance([], Object)
|
|
|
expect('Expected Object, got Array').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('array', () => {
|
|
|
makeInstance([], Array)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, Array)
|
|
|
expect('Expected Array, got Object').toHaveBeenWarned()
|
|
|
})
|
|
|
@@ -226,18 +226,18 @@ describe('Options props', () => {
|
|
|
it('primitive wrapper objects', () => {
|
|
|
/* eslint-disable no-new-wrappers */
|
|
|
makeInstance(new String('s'), String)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(new Number(1), Number)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(new Boolean(true), Boolean)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
/* eslint-enable no-new-wrappers */
|
|
|
})
|
|
|
|
|
|
if (hasSymbol) {
|
|
|
it('symbol', () => {
|
|
|
makeInstance(Symbol('foo'), Symbol)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, Symbol)
|
|
|
expect('Expected Symbol, got Object').toHaveBeenWarned()
|
|
|
})
|
|
|
@@ -257,7 +257,7 @@ describe('Options props', () => {
|
|
|
/* global BigInt */
|
|
|
it('bigint', () => {
|
|
|
makeInstance(BigInt(100), BigInt)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, BigInt)
|
|
|
expect('Expected BigInt, got Object').toHaveBeenWarned()
|
|
|
})
|
|
|
@@ -266,28 +266,28 @@ describe('Options props', () => {
|
|
|
it('custom constructor', () => {
|
|
|
function Class () {}
|
|
|
makeInstance(new Class(), Class)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, Class)
|
|
|
expect('type check failed').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('multiple types', () => {
|
|
|
makeInstance([], [Array, Number, Boolean])
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, [Array, Number, Boolean])
|
|
|
expect('Expected Array, Number, Boolean, got Object').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('custom validator', () => {
|
|
|
makeInstance(123, null, v => v === 123)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(123, null, v => v === 234)
|
|
|
expect('custom validator check failed').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('type check + custom validator', () => {
|
|
|
makeInstance(123, Number, v => v === 123)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(123, Number, v => v === 234)
|
|
|
expect('custom validator check failed').toHaveBeenWarned()
|
|
|
makeInstance(123, String, v => v === 123)
|
|
|
@@ -296,7 +296,7 @@ describe('Options props', () => {
|
|
|
|
|
|
it('multiple types + custom validator', () => {
|
|
|
makeInstance(123, [Number, String, Boolean], v => v === 123)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(123, [Number, String, Boolean], v => v === 234)
|
|
|
expect('custom validator check failed').toHaveBeenWarned()
|
|
|
makeInstance(123, [String, Boolean], v => v === 123)
|
|
|
@@ -305,31 +305,31 @@ describe('Options props', () => {
|
|
|
|
|
|
it('optional with type + null/undefined', () => {
|
|
|
makeInstance(undefined, String)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(null, String)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
})
|
|
|
|
|
|
it('required with type + null/undefined', () => {
|
|
|
makeInstance(undefined, String, null, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(1)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(1)
|
|
|
expect('Expected String').toHaveBeenWarned()
|
|
|
makeInstance(null, Boolean, null, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(2)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(2)
|
|
|
expect('Expected Boolean').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('optional prop of any type (type: true or prop: true)', () => {
|
|
|
makeInstance(1, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance('any', true)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance({}, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(undefined, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
makeInstance(null, true)
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
@@ -468,7 +468,7 @@ describe('Options props', () => {
|
|
|
}
|
|
|
}
|
|
|
}).$mount()
|
|
|
- expect(console.error.mock.calls.length).toBe(0)
|
|
|
+ expect((console.error as any).mock.calls.length).toBe(0)
|
|
|
})
|
|
|
|
|
|
// #3453
|
|
|
@@ -565,7 +565,7 @@ describe('Options props', () => {
|
|
|
})
|
|
|
|
|
|
it('should warn when a prop type is not a constructor', () => {
|
|
|
- const vm = new Vue({
|
|
|
+ new Vue({
|
|
|
template: '<div>{{a}}</div>',
|
|
|
props: {
|
|
|
a: {
|