Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a test to illustrate how to get the root element.
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
var nodeunit = require('nodeunit'); | |||
var path = require('path'); | |||
var xml2object = require('../lib/xml2object'); | |||
|
|||
exports.testRoot = function(test){ | |||
test.expect(2); | |||
|
|||
var parser = new xml2object(['example'], path.normalize(__dirname + '/fixture/input01.xml')); | |||
var found = []; | |||
|
|||
parser.on('object', function(name, obj) { | |||
found.push(obj.foo); | |||
}); | |||
|
|||
parser.on('end', function() { | |||
test.equal(found.length, 1, "Should have found two objects"); | |||
test.equal(found[0], 'bar', 'foobar mismatch'); | |||
|
|||
test.done(); | |||
}); | |||
|
|||
parser.start(); | |||
}; |