Skip to content

Commit

Permalink
add jsx tests, refs #175
Browse files Browse the repository at this point in the history
multi-line comments test now passes with latest esprima-fb; all the other
tests passed previously
  • Loading branch information
jenseng committed Apr 5, 2015
1 parent 2281d1f commit e8eceb1
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/jsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var parse = require("../lib/parser").parse;
var Printer = require("../lib/printer").Printer;
var types = require("../lib/types");

describe("JSX Compatability", function() {
var printer = new Printer({ tabWidth: 2 });

function check(source) {
var ast1 = parse(source);
var ast2 = parse(printer.printGenerically(ast1).code);
types.astNodesAreEquivalent.assert(ast1, ast2);
}

it("should parse and print attribute comments", function() {
check("<b /* comment */ />");
check("<b /* multi\nline\ncomment */ />");
});

it("should parse and print child comments", function() {
check("<b>{/* comment */}</b>");
check("<b>{/* multi\nline\ncomment */}</b>");
});

it("should parse and print literal attributes", function() {
check("<b className=\"hello\" />");
});

it("should parse and print expression attributes", function() {
check("<b className={classes} />");
});

it("should parse and print chidren", function() {
check("<label><input /></label>");
});

it("should parse and print literal chidren", function() {
check("<b>hello world</b>");
});

it("should parse and print expression children", function() {
check("<b>{this.props.user.name}</b>");
});

it("should parse and print namespaced elements", function() {
check("<Foo.Bar />");
});
});

0 comments on commit e8eceb1

Please sign in to comment.