-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: <HtmlSelect> passes custom className to options (+ test)
- Loading branch information
Showing
3 changed files
with
39 additions
and
2 deletions.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
import { assert } from "chai"; | ||
import { EnzymePropSelector, mount, ReactWrapper } from "enzyme"; | ||
import * as React from "react"; | ||
|
||
import { HTMLSelect, IOptionProps } from "../../src/index"; | ||
|
||
describe("<HtmlSelect>", () => { | ||
const emptyHandler = () => { | ||
return; | ||
}; | ||
|
||
it("renders options without CSS classes by default", () => { | ||
const OPTIONS: string[] = ["a", "b"]; | ||
const group = mount(<HTMLSelect onChange={emptyHandler} options={OPTIONS} />); | ||
assert.isUndefined(findOption(group, { value: "a" }).prop("className")); | ||
assert.isUndefined(findOption(group, { value: "b" }).prop("className")); | ||
}); | ||
|
||
it("passes custom classNames to options", () => { | ||
const OPTIONS: IOptionProps[] = [{ className: "apple", value: "a" }, { className: "banana", value: "b" }]; | ||
const group = mount(<HTMLSelect onChange={emptyHandler} options={OPTIONS} />); | ||
assert.strictEqual(findOption(group, { value: "a" }).prop("className"), "apple"); | ||
assert.strictEqual(findOption(group, { value: "b" }).prop("className"), "banana"); | ||
}); | ||
|
||
function findOption(wrapper: ReactWrapper<any, any>, props: EnzymePropSelector) { | ||
return wrapper.find("option").filter(props); | ||
} | ||
}); |
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