Skip to content

Commit

Permalink
Convert Vows assertions to Node.js assertion library
Browse files Browse the repository at this point in the history
  • Loading branch information
awwright committed Jul 13, 2020
1 parent 2d64f58 commit b3ee11a
Show file tree
Hide file tree
Showing 23 changed files with 231 additions and 489 deletions.
2 changes: 2 additions & 0 deletions lib/dom-parser.js
@@ -1,3 +1,5 @@
"use strict";

function DOMParser(options){
this.options = options ||{locator:{}};
}
Expand Down
2 changes: 1 addition & 1 deletion test/3rd-cases/mock.js
@@ -1 +1 @@
exports.test = 1;
exports.test = 1;
114 changes: 0 additions & 114 deletions test/assert.js

This file was deleted.

148 changes: 0 additions & 148 deletions test/assert.vows.js

This file was deleted.

20 changes: 10 additions & 10 deletions test/dom/attr.vows.js
Expand Up @@ -2,24 +2,24 @@

var wows = require('vows');
var DOMParser = require('../../lib/dom-parser').DOMParser;
const assert = require('../assert')
const assert = require('assert');

// Create a Test Suite
wows.describe('XML attrs').addBatch({
"set attribute":function(){
var root = new DOMParser().parseFromString("<xml/>",'text/xml').documentElement;
root.setAttribute('a','1');
assert(root.attributes[0].localName, 'a');
assert.strictEqual(root.attributes[0].localName, 'a');
root.setAttribute('b',2);
root.setAttribute('a',1);
root.setAttribute('a',1);
root.setAttribute('a',1);
assert(root.attributes.length, 2);
assert.strictEqual(root.attributes.length, 2);
try {
var c = root.ownerDocument.createElement('c');
c.setAttributeNode(root.attributes.item(0));
} catch (e) {
assert(e.code, 10);
assert.strictEqual(e.code, 10);
return;
}
assert.fail('expected error but none was thrown');
Expand All @@ -30,30 +30,30 @@ wows.describe('XML attrs').addBatch({
child.setAttributeNS('a','a:a','1');
child.setAttributeNS('b','b:b','2');
child.setAttributeNS('b','b:a','1');
assert(child.attributes.length, 3, 'after adding 3', child);
assert.strictEqual(child.attributes.length, 3, 'after adding 3', child);
child.setAttribute('a',1);
child.setAttributeNS('b','b:b','2');
assert(child.attributes.length, 4, 'after adding 4 and one with namespace');
assert.strictEqual(child.attributes.length, 4, 'after adding 4 and one with namespace');
try {
var c = root.ownerDocument.createElement('c');
c.setAttributeNodeNS(root.attributes.item(0));
} catch (e) {
assert(e.code, 10, 'wrong error code');
assert.strictEqual(e.code, 10, 'wrong error code');
return;
}
assert.fail('expected error but none was thrown');
},
"override attribute":function(){
var root = new DOMParser().parseFromString("<xml xmlns:a='a' xmlns:b='b' xmlns='e'><child/></xml>",'text/xml').documentElement;
root.setAttributeNS('a','a:a','1');
assert(root.attributes.length, 4);
assert.strictEqual(root.attributes.length, 4);
//not standart
// root.firstChild.setAttributeNode(root.attributes[0]);
// assert(root.attributes.length, 0);
// assert.strictEqual(root.attributes.length, 0);
},
"attribute namespace":function(){
var root = new DOMParser().parseFromString("<xml xmlns:a='a' xmlns:b='b' a:b='e'></xml>",'text/xml').documentElement;
assert(root.getAttributeNS("a", "b"), "e");
assert.strictEqual(root.getAttributeNS("a", "b"), "e");
},
"override ns attribute":function(){

Expand Down
30 changes: 15 additions & 15 deletions test/dom/clone.vows.js
Expand Up @@ -3,24 +3,24 @@
var wows = require('vows');
var XMLSerializer = require('../../lib/dom-parser').XMLSerializer;
var DOMParser = require('../../lib/dom-parser').DOMParser;
const assert = require('../assert')
const assert = require('assert');

// Create a Test Suite
wows.describe('XML Namespace Parse').addBatch({
'clone': function () {
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml')
'clone': function () {
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml');
var doc1s = new XMLSerializer().serializeToString(doc1);
var n =doc1.cloneNode(true)
assert(n, doc1s)
},
'import': function () {
var doc1 = new DOMParser().parseFromString("<doc2 attr='2'/>")
var doc2 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml')
var n =doc1.cloneNode(true);
assert(n, doc1s);
},
'import': function () {
var doc1 = new DOMParser().parseFromString("<doc2 attr='2'/>");
var doc2 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml');

var doc3 = new DOMParser().parseFromString("<doc2 attr='2'><doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1></doc2>")
var n =doc1.importNode(doc2.documentElement, true)
doc1.documentElement.appendChild(n)
assert(doc1, doc3+'')
assert.isTrue(doc2 != doc3+'')
}
var doc3 = new DOMParser().parseFromString("<doc2 attr='2'><doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1></doc2>");
var n =doc1.importNode(doc2.documentElement, true);
doc1.documentElement.appendChild(n);
assert.equal(doc1, doc3+'');
assert(doc2 != doc3+'');
},
}).export(module); // Run it

0 comments on commit b3ee11a

Please sign in to comment.