vuejs unit test include autobahn

#1

hi,
i want to unit test my vuejs code…

and,my home.vue code:

mounted () {

var fileServer = packageData.fileServer

this.actionUrl = fileServer + '/file_upload'

this.connection = new autobahn.Connection({

  url: 'ws://' + packageData.crossbarServer + '/ws',

  realm: 'realm1'

})

this.connection.onclose = (reason, details) => {

  console.log('Connection lost: ' + reason)

}

this.connection.onopen = (session, details) => {

  this.autobahnSession = session

}

this.connection.open()

},

and my unit test code is :

before(() => {

Home.mounted()

Home.connection.onopen()

})

it(‘test’, () => {

console.log(Home.autobahnSession)

})

and my terminal shows error :

Home.autobahnSession is undefined.

I find the question, i didn’t get session , session is undefined.

how should i do to get session value???

And how should i do to unit test my code that include autobahn???

thanks a lot!!!

···
0 Likes

#2

and now
when i npm run unit
it shows error:

the string “session not open” was thrown, throw an Error :slight_smile:

what’s wrong with it ?

and how should i do to unit test include autobahn???

thanks a lot!
在 2017年11月1日星期三 UTC+8上午10:49:54,1352…@163.com写道:

···

hi,
i want to unit test my vuejs code…

and,my home.vue code:

mounted () {

var fileServer = packageData.fileServer
this.actionUrl = fileServer + '/file_upload'
this.connection = new autobahn.Connection({
  url: 'ws://' + packageData.crossbarServer + '/ws',
  realm: 'realm1'
})
this.connection.onclose = (reason, details) => {
  console.log('Connection lost: ' + reason)
}
this.connection.onopen = (session, details) => {
  this.autobahnSession = session
}
this.connection.open()

},

and my unit test code is :

before(() => {

Home.mounted()
Home.connection.onopen()

})

it(‘test’, () => {

console.log(Home.autobahnSession)

})

and my terminal shows error :

Home.autobahnSession is undefined.

I find the question, i didn’t get session , session is undefined.

how should i do to get session value???

And how should i do to unit test my code that include autobahn???

thanks a lot!!!

0 Likes