X Tutup
Skip to content

introduce hasStyle value#5371

Closed
matsko wants to merge 3 commits intoangular:masterfrom
matsko:matcher_fixes
Closed

introduce hasStyle value#5371
matsko wants to merge 3 commits intoangular:masterfrom
matsko:matcher_fixes

Conversation

@matsko
Copy link
Copy Markdown
Contributor

@matsko matsko commented Nov 19, 2015

No description provided.

@matsko matsko force-pushed the matcher_fixes branch 2 times, most recently from 0cf7223 to 90d7c34 Compare November 19, 2015 22:29
@IgorMinar
Copy link
Copy Markdown
Contributor

needs to be rebased and CI is failing. otherwise it looks reasonable. @juliemr can you take a look too please?

@pkozlowski-opensource
Copy link
Copy Markdown
Member

I would love to have this matcher, would come handy in few tests I've written before (ex. ones for NgStyle and some integration tests)

@matsko
Copy link
Copy Markdown
Contributor Author

matsko commented Nov 20, 2015

Rebased on master.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Style nitpick: We don't really need the custom negativeCompare here. Instead I'd do:

    toHaveCssStyle: function() {
      return {compare: {
        return function(actual, styles) {
          var allPassed;
          if (isString(styles)) {
            allPassed = DOM.hasStyle(actual, styles);
          } else {
            allPassed = !StringMapWrapper.isEmpty(styles);
            StringMapWrapper.forEach(styles, (style, prop) => {
              allPassed = allPassed && DOM.hasStyle(actual, prop, style);
            });
          }

          return {
            pass: allPassed,
            get message() {
              var expectedValueStr = isString(styles) ? styles : JSON.stringify(styles);
              return `Expected ${actual.outerHTML} ${!allPassed ? 'not ' : ''} to contain the
                      CSS ${isString(styles) ? 'property' : 'styles'} "${expectedValueStr}"`;
            }
          };
        };
      }
    },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes sense up to the point where we use !allPassed to turn on the "not " token within the error message. That doesn't look right.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's the recommended way in the Jasmine docs though - if it didn't pass but we're throwing an error, we know the check was with a .not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True. OK. I've updated the changes and force pushed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI still not happy
On Fri, Nov 20, 2015 at 9:50 AM Matias Niemelä notifications@github.com
wrote:

In modules/angular2/src/testing/matchers.ts
#5371 (comment):

@@ -105,6 +107,33 @@ _global.beforeEach(function() {
}
},

  • toHaveCssStyle: function() {
  •  return {compare: buildError(false), negativeCompare: buildError(true)};
    

True. OK. I've updated the changes and force pushed.


Reply to this email directly or view it on GitHub
https://github.com/angular/angular/pull/5371/files#r45496685.

@juliemr
Copy link
Copy Markdown
Member

juliemr commented Nov 20, 2015

Looks good to me except for one optional nitpick.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it should be the other way around: !allPassed ? '' : 'not'

@matsko matsko force-pushed the matcher_fixes branch 4 times, most recently from 6c566e5 to 0a9bff4 Compare November 21, 2015 00:00
@matsko matsko added the action: merge The PR is ready for merge by the caretaker label Nov 21, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty minor, but ' ' should be '' to avoid excess whitespace.

@mary-poppins
Copy link
Copy Markdown

Merging PR #5371 on behalf of @alxhub to branch presubmit-alxhub-pr-5371.

@matsko matsko closed this in 564642d Nov 23, 2015
@matsko matsko deleted the matcher_fixes branch November 14, 2016 21:05
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

X Tutup