2017-10-12 3 views
0

Ich habe diesen Test:Jest toEqual nicht aufgrund Format JSON vorbei

it('Outputs correct ES6 code',() => { 

    const updateCodeGenerationOptions = actions.updateSourceCode(sampleJson) 
    expect(jsonCodeTools(undefined, updateCodeGenerationOptions)) 
    .toEqual(
     { 
     'options': {'outputCodeType': 'ES6'}, 
     'outputCodeFromJSON': '<pre>export class Foo {<br> constructor (object) {<br> this.shouldBeNumber1 = object.shouldBeNumber1; <br> this.shouldBeString1 = object.shouldBeString1; <br> this.shouldBeBoolean1 = object.shouldBeBoolean1; <br> this.shouldBeFragment1 = new shouldBeFragment1(object.shouldBeFragment1); <br> } <br>}<br>export class shouldBeFragment1{<br> constructor (object) {<br> this.FshouldBeNumber1 = object.FshouldBeNumber1; <br> this.FshouldBeString1 = object.FshouldBeString1; <br> this.FshouldBeBoolean1 = object.FshouldBeBoolean1; <br> } <br>}<br></pre>', 
     'sourceCode': JSON.stringify({ 
      'shouldBeNumber1': '1', 
      'shouldBe String1': '.1', 
      'shouldBeBoolean1': 'false', 
      'shouldBeFragment1': { 
      'FshouldBeNumber1': '1', 
      'FshouldBeString1': 'bar', 
      'FshouldBeBoolean1': 'false' 
      } 
     }) 
     } 
    ) 
}) 

Wenn es läuft es mit diesem fehlschlägt:

enter image description here

Also ich ist dies nur eine Formating Ausgabe Wie würde ich diesen Test bestehen?

Antwort

0

Sie haben ein Formatierungsproblem, aber Ihr Test ist wirklich nicht bestanden. Schau dir shouldBeFragment1 an; erwarteter Wert ist falsch, aber der tatsächliche Wert ist ein Objekt.

Für das Formatierungsproblem sollten Sie JSON.parse und dann JSON.stringify die tatsächliche Ausgabe, so dass es nicht schön gedruckt wird (oder besser noch entfernen Sie die hübsche Druck von der Einheit im Test).

+0

shouldBeefragment1 wird nicht erwartet, falsch zu sein – Nikos

+0

Nun, die Jest-Ausgabe sagt, dass es voraussichtlich falsch sein wird. Damit. –

+0

Ich kann nicht sehen können Sie zeigen? – Nikos