dimanche 12 août 2018

Vue.js testing toBe() method return only object when expected 'string' etc

I am learning testing a Vue.js apps. And I wanted to test data of my root component. Here is my code

import { mount } from '@vue/test-utils' import App from '../../src/App'

describe('App', ()=>{
test('App is the component of Vue', ()=>{
    const wrapper = mount(App)
    expect(wrapper.isVueInstance()).toBeTruthy()
})

test("App's fetched data is an object",()=>{
    expect(typeof App.data().fetchedData).toBe('object')
})
test("App's weather city is a string",()=>{
    expect(typeof App.data().weatherData.city).toBe('string')
})

}) 

here is my App.vue code:

data() {
return {
  city: "New York",
  fetchedData: null,
  weatherData: {
    city: null,
    temperature: null,
    humidity: null,
    pressure: null,
    speed: null,
    weather: null,
    icon: null
  },
  forecastData: null
};   
 },
  methods:{
 setData() {
  this.weatherData.city = this.fetchedData.data.city.name;
  this.weatherData.temperature = this.fetchedData.data.list[0].temp.day;
  this.weatherData.humidity = this.fetchedData.data.list[0].humidity;
  this.weatherData.pressure = this.fetchedData.data.list[0].pressure;
  this.weatherData.speed = this.fetchedData.data.list[0].speed;
  this.weatherData.icon = this.fetchedData.data.list[0].weather[0].icon;
  this.weatherData.weather = this.fetchedData.data.list[0].weather[0].main;
  this.forecastData = this.fetchedData.data.list.slice(1, 5);
}
}

tests toBe() method returns object for every element

Aucun commentaire:

Enregistrer un commentaire