{"action":"created","issue":{"url":"https://api.github.com/repos/cypress-io/cypress/issues/5351","repository_url":"https://api.github.com/repos/cypress-io/cypress","labels_url":"https://api.github.com/repos/cypress-io/cypress/issues/5351/labels{/name}","comments_url":"https://api.github.com/repos/cypress-io/cypress/issues/5351/comments","events_url":"https://api.github.com/repos/cypress-io/cypress/issues/5351/events","html_url":"https://github.com/cypress-io/cypress/issues/5351","id":505901892,"node_id":"MDU6SXNzdWU1MDU5MDE4OTI=","number":5351,"title":"Alias created in before() only works on first test (but it's only used in the second test)","user":{"login":"dsesami","id":19942822,"node_id":"MDQ6VXNlcjE5OTQyODIy","avatar_url":"https://avatars1.githubusercontent.com/u/19942822?v=4","gravatar_id":"","url":"https://api.github.com/users/dsesami","html_url":"https://github.com/dsesami","followers_url":"https://api.github.com/users/dsesami/followers","following_url":"https://api.github.com/users/dsesami/following{/other_user}","gists_url":"https://api.github.com/users/dsesami/gists{/gist_id}","starred_url":"https://api.github.com/users/dsesami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsesami/subscriptions","organizations_url":"https://api.github.com/users/dsesami/orgs","repos_url":"https://api.github.com/users/dsesami/repos","events_url":"https://api.github.com/users/dsesami/events{/privacy}","received_events_url":"https://api.github.com/users/dsesami/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2019-10-11T14:56:38Z","updated_at":"2020-01-03T08:42:07Z","closed_at":"2019-10-25T15:49:23Z","author_association":"NONE","body":"###  Update 10/16: See https://github.com/cypress-io/cypress/issues/5351#issuecomment-542779224 for a clearer example and explanation.\r\n\r\n\r\n### Original Post Below This Line\r\n### ------------------------------------------\r\nThis appears to be really similar to https://github.com/cypress-io/cypress/issues/2766 (and https://github.com/cypress-io/cypress/issues/665 in turn), but it seems like it's a bit different. The alias definition exists, like `user` as an object exists, and `user.id` exists, but the value of `user.id` is null.\r\n\r\nNote that an alias created _within_ the second test doesn't appear to work -- \r\n\r\n```js\r\nit('does something', function () {\r\n  cy.createUser('xyz').as('user') // createUser is an exec() outside of the application\r\n  this.user.something... \r\n    // expected this to be available, \r\n    // as this works if I stuck it into a beforeEach \r\n    // on any test, or a before on the first test\r\n})\r\n```\r\n\r\n### Current behavior:\r\nThe before() hook contains an alias. I would expect `this` to have `this.user` available as an object. If it is in the first test (I copy and move the test to the top), the test works. However, after the first test, `this.user` exists, but its value is empty and undefined.\r\n### Desired behavior:\r\nI would expect `this.user` to remain a consistent object available throughout each test in the spec file. I can currently get around this with `cy.createUser().then((user) => )`, but that's why I wanted to use aliases in the first place. Alternatively, I'd expect an alias to be create-able within a test.\r\n\r\n### Steps to reproduce:\r\n\r\nTest setup:\r\n```js\r\nbefore(function() {\r\n  cy.createUser('foo').as('user') // returns an object that has a value called user.id\r\n})\r\n\r\nit('is the first test') {\r\n // nothing happens here\r\n}\r\n\r\nit('is a second test') {\r\n  cy.visit(`/users/${this.user.id}`)\r\n}\r\n```\r\n### Versions\r\nLatest cypress (Oct 11 2019), chrome, fedora.\r\n\r\nIf you need more info, please feel free to ask."},"comment":{"url":"https://api.github.com/repos/cypress-io/cypress/issues/comments/570504423","html_url":"https://github.com/cypress-io/cypress/issues/5351#issuecomment-570504423","issue_url":"https://api.github.com/repos/cypress-io/cypress/issues/5351","id":570504423,"node_id":"MDEyOklzc3VlQ29tbWVudDU3MDUwNDQyMw==","user":{"login":"jennifer-shehane","id":1271364,"node_id":"MDQ6VXNlcjEyNzEzNjQ=","avatar_url":"https://avatars1.githubusercontent.com/u/1271364?v=4","gravatar_id":"","url":"https://api.github.com/users/jennifer-shehane","html_url":"https://github.com/jennifer-shehane","followers_url":"https://api.github.com/users/jennifer-shehane/followers","following_url":"https://api.github.com/users/jennifer-shehane/following{/other_user}","gists_url":"https://api.github.com/users/jennifer-shehane/gists{/gist_id}","starred_url":"https://api.github.com/users/jennifer-shehane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennifer-shehane/subscriptions","organizations_url":"https://api.github.com/users/jennifer-shehane/orgs","repos_url":"https://api.github.com/users/jennifer-shehane/repos","events_url":"https://api.github.com/users/jennifer-shehane/events{/privacy}","received_events_url":"https://api.github.com/users/jennifer-shehane/received_events","type":"User","site_admin":false},"created_at":"2020-01-03T08:42:06Z","updated_at":"2020-01-03T08:42:06Z","author_association":"MEMBER","body":"@dsesami We updated the scope of the original issue to issue a warning when defining an alias in a before, please direct all comments to the original issue. https://github.com/cypress-io/cypress/issues/665#issuecomment-552961024"}}
{"actor":{"display_login":"jennifer-shehane"}}