Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix conditional to ensure we catch properties with a falsy value #423

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __tests__/__output/json-nested.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"color": {
"base": {
"red": {
"primary": "#611D1C",
"secondary": {
"inverse": "#000000"
}
}
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where this came from... Is this ok @dbanksdesign ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a race condition in our unit tests somewhere.. there shouldn't be anything checked into tests/__output/ that is the folder where we put files generated by the unit tests. It should get cleared after tests run. You can remove this file or just try running the tests again and see if it gets removed.

50 changes: 50 additions & 0 deletions __tests__/filterProperties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ var sizeLarge = {
]
}

var not_kept = {
"value": 0,
"original": {
"value": 0,
},
"name": "falsy_values-not_kept",
"attributes": { category: "falsy_values" },
"path": [
"falsy_values",
"not_kept"
]
}

var kept = {
"value": 0,
"original": {
"value": 0,
},
"name": "falsy_values-kept",
"attributes": { category: "falsy_values" },
"path": [
"falsy_values",
"kept"
]
}

var properties = {
"color": {
"red": colorRed,
Expand All @@ -79,11 +105,21 @@ var properties = {
}
};

var falsy_values = {
"kept": kept,
"not_kept": not_kept,
};

var dictionary = {
"properties": properties,
"allProperties": flattenProperties(properties)
}

var falsy_dictionary = {
"properties": falsy_values,
"allProperties": flattenProperties(falsy_values)
}

describe('filterProperties', () => {

beforeEach(() => {
Expand Down Expand Up @@ -112,6 +148,20 @@ describe('filterProperties', () => {
expect(filteredDictionary.properties).not.toHaveProperty('color');
});

it('should work with falsy values and a filter function', () => {
var filter = function(property) {
return property.path.includes("kept");
}

var filteredDictionary = filterProperties(falsy_dictionary, filter);
_.each(filteredDictionary.allProperties, function(property) {
expect(property).not.toBe(not_kept);
});
expect(filteredDictionary.allProperties).toEqual([kept]);
expect(filteredDictionary.properties).toHaveProperty('kept');
expect(filteredDictionary.properties).not.toHaveProperty('not_kept');
});

describe('should throw if', () => {
it('filter is a string', () => {
expect(
Expand Down