Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the data API to function type #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions test/cases/backward/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ test.serial('`created`, `attached`, `ready`, `moved`, `detached` should be calle

test.serial('`data` could be defined by `Component.define({ data })', (t) => {
Tina.Component.define({
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
})
t.deepEqual(t.context.mina.globals.Component.lastCall.args[0].data, { foo: 'bar' } )
Expand Down Expand Up @@ -109,8 +111,10 @@ test.serial('`observers` could be triggered', async (t) => {
value: 'quux',
},
},
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
observers: {
qux: sinon.spy(),
Expand Down Expand Up @@ -170,8 +174,10 @@ test.serial('`observers` could access methods', async (t) => {
test.serial('`this.data` could be accessed', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.data)
Expand All @@ -195,8 +201,10 @@ test.serial.skip('`this.properties` could be accessed', async (t) => {
value: 'quux',
},
},
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.properties)
Expand Down Expand Up @@ -239,8 +247,10 @@ test.serial('`properties` should be merged with `data`', async (t) => {
value: 'quux',
},
},
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
}
Tina.Component.define(options)
Expand Down Expand Up @@ -350,8 +360,10 @@ test.serial('`methods` could be called in context of Tina.Component instance', a

test.serial('`this.setData(patch)` could update data', async (t) => {
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
attached () {
this.setData({
Expand All @@ -372,8 +384,10 @@ test.serial('`this.setData(patch)` could update data', async (t) => {
test.serial('`this.setData(patch, callback)` could update data and then execute callback', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
attached () {
this.setData({
Expand All @@ -396,8 +410,10 @@ test.serial('`this.setData(patch, callback)` could update data and then execute
test.serial('`this.hasBehavior` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.hasBehavior)
Expand All @@ -415,8 +431,10 @@ test.serial('`this.hasBehavior` method should exist', async (t) => {
test.serial('`this.triggerEvent` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.triggerEvent)
Expand All @@ -434,8 +452,10 @@ test.serial('`this.triggerEvent` method should exist', async (t) => {
test.serial('`this.createSelectorQuery` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.createSelectorQuery)
Expand All @@ -453,8 +473,10 @@ test.serial('`this.createSelectorQuery` method should exist', async (t) => {
test.serial('`this.selectComponent` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.selectComponent)
Expand All @@ -472,8 +494,10 @@ test.serial('`this.selectComponent` method should exist', async (t) => {
test.serial('`this.selectAllComponents` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.selectAllComponents)
Expand All @@ -491,8 +515,10 @@ test.serial('`this.selectAllComponents` method should exist', async (t) => {
test.serial('`this.getRelationNodes` method should exist', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
created () {
spy(this.getRelationNodes)
Expand Down Expand Up @@ -555,8 +581,10 @@ test.serial('`pageLifetimes` can be triggered', async (t) => {
spy(this.data.foo)
},
},
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
}

Expand Down
24 changes: 16 additions & 8 deletions test/cases/backward/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ test.serial('`before` hooks should called before `on` hooks', async (t) => {

test.serial('`data` could be defined by `Page.define({ data })`', (t) => {
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
}
Tina.Page.define(options)
Expand All @@ -122,8 +124,10 @@ test.serial('`data` could be defined by `Page.define({ data })`', (t) => {
test.serial('`this.data` could be accessed', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
onLoad () {
spy(this.data)
Expand Down Expand Up @@ -181,8 +185,10 @@ test.serial('`methods` could be called in context of Tina.Page instance', async

test.serial('`this.setData(patch)` could update data', async (t) => {
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
onLoad () {
this.setData({
Expand All @@ -202,8 +208,10 @@ test.serial('`this.setData(patch)` could update data', async (t) => {
test.serial('`this.setData(patch, callback)` could update data and then execute callback', async (t) => {
const spy = sinon.spy()
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
onLoad () {
this.setData({
Expand Down
12 changes: 8 additions & 4 deletions test/cases/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ test.afterEach((t) => {

test.serial('`compute` should be called and merged with `data` by Page', async (t) => {
const options = {
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
compute (state) {
return {
Expand All @@ -42,8 +44,10 @@ test.serial('`compute` should be called and merged with `data` by Component', as
value: 'quux',
},
},
data: {
foo: 'bar',
data () {
return {
foo: 'bar',
}
},
compute (state) {
return {
Expand Down