Skip to content

Commit 30de71e

Browse files
committed
Add more tests for NOT
1 parent a892805 commit 30de71e

File tree

2 files changed

+187
-1
lines changed

2 files changed

+187
-1
lines changed

src/__tests__/index.spec.js

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,192 @@ describe("media queries", () => {
659659
).toEqual({ a: 2 });
660660
});
661661

662+
it("should process media query with NOT and OR operators and type", () => {
663+
expect(
664+
process({
665+
__mediaQueries: {
666+
"@media not print, (orientation: landscape)": [
667+
{
668+
inverse: true,
669+
type: "print",
670+
expressions: []
671+
},
672+
{
673+
expressions: [
674+
{
675+
feature: "orientation",
676+
modifier: undefined,
677+
value: "landscape"
678+
}
679+
],
680+
inverse: false,
681+
type: "all"
682+
}
683+
],
684+
"@media print": [
685+
{
686+
inverse: false,
687+
type: "print",
688+
expressions: []
689+
}
690+
]
691+
},
692+
a: 1,
693+
"@media not print, (orientation: landscape)": {
694+
a: 2
695+
},
696+
"@media print": {
697+
a: 3
698+
}
699+
})
700+
).toEqual({ a: 2 });
701+
expect(
702+
process({
703+
__mediaQueries: {
704+
"@media not ios, (orientation: landscape)": [
705+
{
706+
inverse: true,
707+
type: "ios",
708+
expressions: []
709+
},
710+
{
711+
expressions: [
712+
{
713+
feature: "orientation",
714+
modifier: undefined,
715+
value: "landscape"
716+
}
717+
],
718+
inverse: false,
719+
type: "all"
720+
}
721+
],
722+
"@media print": [
723+
{
724+
inverse: false,
725+
type: "print",
726+
expressions: []
727+
}
728+
]
729+
},
730+
a: 1,
731+
"@media not ios, (orientation: landscape)": {
732+
a: 2
733+
},
734+
"@media print": {
735+
a: 3
736+
}
737+
})
738+
).toEqual({ a: 2 });
739+
expect(
740+
process({
741+
__mediaQueries: {
742+
"@media not print, (orientation: portrait)": [
743+
{
744+
inverse: true,
745+
type: "print",
746+
expressions: []
747+
},
748+
{
749+
expressions: [
750+
{
751+
feature: "orientation",
752+
modifier: undefined,
753+
value: "portrait"
754+
}
755+
],
756+
inverse: false,
757+
type: "all"
758+
}
759+
],
760+
"@media print": [
761+
{
762+
inverse: false,
763+
type: "print",
764+
expressions: []
765+
}
766+
]
767+
},
768+
a: 1,
769+
"@media not ios, (orientation: portrait)": {
770+
a: 2
771+
},
772+
"@media print": {
773+
a: 3
774+
}
775+
})
776+
).toEqual({ a: 1 });
777+
});
778+
779+
it("should process media query with NOT and AND operators and platform", () => {
780+
expect(
781+
process({
782+
__mediaQueries: {
783+
"@media android": [
784+
{
785+
inverse: false,
786+
type: "android",
787+
expressions: []
788+
}
789+
],
790+
"@media not android and (orientation: landscape)": [
791+
{
792+
inverse: true,
793+
type: "android",
794+
expressions: [
795+
{
796+
feature: "orientation",
797+
modifier: undefined,
798+
value: "landscape"
799+
}
800+
]
801+
}
802+
]
803+
},
804+
a: 1,
805+
"@media android": {
806+
a: 2
807+
},
808+
"@media not ios and (orientation: landscape)": {
809+
a: 3
810+
}
811+
})
812+
).toEqual({ a: 1 });
813+
expect(
814+
process({
815+
__mediaQueries: {
816+
"@media android": [
817+
{
818+
inverse: false,
819+
type: "android",
820+
expressions: []
821+
}
822+
],
823+
"@media not android and (orientation: portrait)": [
824+
{
825+
inverse: true,
826+
type: "android",
827+
expressions: [
828+
{
829+
feature: "orientation",
830+
modifier: undefined,
831+
value: "portrait"
832+
}
833+
]
834+
}
835+
]
836+
},
837+
a: 1,
838+
"@media android": {
839+
a: 2
840+
},
841+
"@media not android and (orientation: portrait)": {
842+
a: 3
843+
}
844+
})
845+
).toEqual({ a: 3 });
846+
});
847+
662848
it("should process media query with not operator and platform", () => {
663849
expect(
664850
process({

src/mediaquery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function matchQuery(query, values) {
9494
}
9595
});
9696

97-
return (expressionsMatch && !inverse) || (!expressionsMatch && inverse);
97+
return expressionsMatch || inverse;
9898
}
9999

100100
// -- Utilities ----------------------------------------------------------------

0 commit comments

Comments
 (0)