Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngneat/spectator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.9.1
Choose a base ref
...
head repository: ngneat/spectator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.9.2
Choose a head ref
  • 3 commits
  • 3 files changed
  • 3 contributors

Commits on Jun 11, 2019

  1. Copy the full SHA
    fd7c947 View commit details

Commits on Jun 13, 2019

  1. fix(matchers): visibility matchers work with Jest (#113)

    fix(matchers): visibility matchers work with Jest
    NetanelBasal authored Jun 13, 2019
    Copy the full SHA
    843c5df View commit details

Commits on Jun 21, 2019

  1. Copy the full SHA
    b608473 View commit details
Showing with 41 additions and 12 deletions.
  1. +1 −1 projects/spectator/package.json
  2. +5 −1 projects/spectator/src/lib/http.ts
  3. +35 −10 projects/spectator/src/lib/matchers.ts
2 changes: 1 addition & 1 deletion projects/spectator/package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "@netbasal/spectator",
"description": "Angular tests made easy",
"author": "Netanel Basal <netanel7799s@gmail.com>",
"version": "3.9.1",
"version": "3.9.2",
"license": "MIT",
"repository": {
"type": "git",
6 changes: 5 additions & 1 deletion projects/spectator/src/lib/http.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,11 @@ export enum HTTPMethod {
GET = 'GET',
POST = 'POST',
DELETE = 'DELETE',
PUT = 'PUT'
PUT = 'PUT',
PATCH = 'PATCH',
HEAD = 'HEAD',
JSONP = 'JSONP',
OPTIONS = 'OPTIONS'
}

export class SpectatorHTTP<T> {
45 changes: 35 additions & 10 deletions projects/spectator/src/lib/matchers.ts
Original file line number Diff line number Diff line change
@@ -240,18 +240,42 @@ export const toBeEmpty = comparator(el => {
});

/**
* The :hidden selector selects hidden elements.
* Hidden elements are elements that are:
* 1. Set to display:none
* Hidden elements are elements that have:
* 1. Display property set to "none"
* 2. Width and height set to 0
* 3. A hidden parent element (this also hides child elements)
* 4. Form elements with type="hidden"
* 4. Type equal to "hidden" (only for form elements)
* 5. A "hidden" attribute
*/
function isHidden(el) {
while (el) {
if (el === document) {
break;
}

if (!(el.offsetWidth || el.offsetHeight || el.getClientRects().length) || el.style.display === 'none' || el.style.visibility === 'hidden' || el.type === 'hidden' || el.hasAttribute('hidden')) {
return true;
}

el = el.parentNode;
}

return false;
}

/**
* Hidden elements are elements that have:
* 1. Display property set to "none"
* 2. Width and height set to 0
* 3. A hidden parent element (this also hides child elements)
* 4. Type equal to "hidden" (only for form elements)
* 5. A "hidden" attribute
*
* expect('div').toBeHidden();
*
* */
export const toBeHidden = comparator(el => {
const pass = $(el).is(':hidden');
const pass = isHidden(el);
const message = () => `Expected element${pass ? ' not' : ''} to be hidden`;
return { pass, message };
});
@@ -269,18 +293,19 @@ export const toBeSelected = comparator(el => {
});

/**
* The :visible selector selects hidden elements.
* Hidden elements are elements that are:
* 1. Set to display:none
* Hidden elements are elements that have:
* 1. Display property set to "none"
* 2. Width and height set to 0
* 3. A hidden parent element (this also hides child elements)
* 4. Form elements with type="hidden"
* 4. Type equal to "hidden" (only for form elements)
* 5. A "hidden" attribute
*
* expect('div').toBeVisible();
*
* */
export const toBeVisible = comparator(el => {
const pass = $(el).is(':visible');
const pass = !isHidden(el);

const message = () => `Expected element${pass ? ' not' : ''} to be visible`;
return { pass, message };
});