Last active
February 18, 2020 13:33
-
-
Save pipopotamasu/282f8d43a70346b24187b1d20ab551d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SomeComponent.vue | |
export default { | |
props: { | |
a: { | |
type: Number | |
} | |
}, | |
date () { | |
return { | |
b: 1, | |
liked: false | |
} | |
} | |
~~~~~~~~~~ | |
methods: { | |
sayHi () { | |
return 'Hi' | |
} | |
add (c) { | |
return this.a + this.b + c | |
}, | |
like () { | |
this.liked = !this.liked | |
}, | |
recommend () { | |
if (this.liked) { | |
this.notify() | |
} else { | |
alert('should like before recommend.') | |
} | |
} | |
} | |
} | |
// Button.spec.js | |
import tester from 'vue-function-tester'; | |
import SomeComponent from 'SomeComponent.vue'; | |
describe('methods', () => { | |
const { saiHi, add, like, recomend } = tester.methods(SomeComponent); | |
describe('hello', () => { | |
it('returns Hi', () => { | |
// run() returns result object | |
expect(saiHi().run().return).toBe('Hi') | |
}); | |
}); | |
describe('add', () => { | |
it('returns 6', () => { | |
expect(add(3).run({ a: 1, b: 2 }).return).toBe(6) | |
}); | |
}); | |
describe('like', () => { | |
it('is true', () => { | |
const result = like().run({ liked: false }) | |
expect(result.liked).toBe(true) | |
expect(result.return).toBe(undefined) | |
}); | |
}); | |
describe('recommend', () => { | |
describe('liked = true', { | |
it('calls notify', () => { | |
const result = recommend().run({ liked: false }); | |
expect(result.notify.calls).toEqual([[]]) | |
expect(result.notify.called).toBe(true) | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment