Skip to content

Commit 5aaf863

Browse files
committedFeb 23, 2019
test: fix tests
1 parent 9153444 commit 5aaf863

File tree

2 files changed

+21
-44
lines changed

2 files changed

+21
-44
lines changed
 

‎test/NumberField_test.js

+17-23
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ describe("NumberField", () => {
291291
expect(node.querySelector("select").id).eql("root");
292292
});
293293

294-
it("should render a select element if set the enum.", () => {
294+
it("should render a select element with a blank option, when default value is not set.", () => {
295295
const schema = {
296296
type: "object",
297297
properties: {
@@ -307,16 +307,21 @@ describe("NumberField", () => {
307307
});
308308

309309
const selects = node.querySelectorAll("select");
310-
expect(selects).to.have.length.of(1);
310+
expect(selects[0].value).eql("");
311+
312+
const options = node.querySelectorAll("option");
313+
expect(options.length).eql(2);
314+
expect(options[0].innerHTML).eql("");
311315
});
312316

313-
it("should render a select element and it's value is empty, if set the enum and the default value is undefined.", () => {
317+
it("should render a select element without a blank option, if a default value is set.", () => {
314318
const schema = {
315319
type: "object",
316320
properties: {
317321
foo: {
318322
type: "number",
319-
enum: [0],
323+
enum: [2],
324+
default: 2,
320325
},
321326
},
322327
};
@@ -326,29 +331,14 @@ describe("NumberField", () => {
326331
});
327332

328333
const selects = node.querySelectorAll("select");
329-
expect(selects[0].value).eql("");
330-
});
331-
332-
it("should render a select element and it's first option has an empty innerHTML, if set the enum and the default value is undefined.", () => {
333-
const schema = {
334-
type: "object",
335-
properties: {
336-
foo: {
337-
type: "number",
338-
enum: [0],
339-
},
340-
},
341-
};
342-
343-
const { node } = createFormComponent({
344-
schema,
345-
});
334+
expect(selects[0].value).eql("2");
346335

347336
const options = node.querySelectorAll("option");
348-
expect(options[0].innerHTML).eql("");
337+
expect(options.length).eql(1);
338+
expect(options[0].innerHTML).eql("2");
349339
});
350340

351-
it("should render a select element and it's first option is '0', if set the enum and the default value is 0.", () => {
341+
it("should render a select element without a blank option, if the default value is 0.", () => {
352342
const schema = {
353343
type: "object",
354344
properties: {
@@ -364,7 +354,11 @@ describe("NumberField", () => {
364354
schema,
365355
});
366356

357+
const selects = node.querySelectorAll("select");
358+
expect(selects[0].value).eql("0");
359+
367360
const options = node.querySelectorAll("option");
361+
expect(options.length).eql(1);
368362
expect(options[0].innerHTML).eql("0");
369363
});
370364
});

‎test/StringField_test.js

+4-21
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ describe("StringField", () => {
351351
expect(node.querySelector("#custom")).to.exist;
352352
});
353353

354-
it("should render a select element and it's first option is 'false', if set the enum and the default value is false.", () => {
354+
it("should render a select element with first option 'false' if the default value is false", () => {
355355
const schema = {
356356
type: "object",
357357
properties: {
@@ -369,25 +369,6 @@ describe("StringField", () => {
369369

370370
const options = node.querySelectorAll("option");
371371
expect(options[0].innerHTML).eql("false");
372-
});
373-
374-
it("should render a select element and the option's length is equal the enum's length, if set the enum.", () => {
375-
const schema = {
376-
type: "object",
377-
properties: {
378-
foo: {
379-
type: "string",
380-
enum: [false, true],
381-
default: false,
382-
},
383-
},
384-
};
385-
386-
const { node } = createFormComponent({
387-
schema,
388-
});
389-
390-
const options = node.querySelectorAll("option");
391372
expect(options.length).eql(2);
392373
});
393374

@@ -408,10 +389,11 @@ describe("StringField", () => {
408389
});
409390

410391
const options = node.querySelectorAll("option");
392+
expect(options[0].innerHTML).eql("");
411393
expect(options.length).eql(2);
412394
});
413395

414-
it("shouldn't render two empty options, when the default value is empty.", () => {
396+
it("should render only one empty option when the default value is empty.", () => {
415397
const schema = {
416398
type: "object",
417399
properties: {
@@ -428,6 +410,7 @@ describe("StringField", () => {
428410
});
429411

430412
const options = node.querySelectorAll("option");
413+
expect(options[0].innerHTML).eql("");
431414
expect(options.length).eql(1);
432415
});
433416
});

0 commit comments

Comments
 (0)
Please sign in to comment.