> For the complete documentation index, see [llms.txt](https://scope.onepub.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scope.onepub.dev/fundamentals/scope/detecting.md).

# Detecting

It can often be useful to determine if you are running in a Scope.

You can detect if your code is running within a Scope by calling:

```dart
Scope.isWithinScope();

// or

isWithinScope();
```

You can also detect if a specific ScopeKey exists by calling:

```dart
if (hasScopeKey(ageKey))
{
   // change my behaviour
}

/// or

if (Scope.hasScopeKey(ageKey))
{
   // change my behaviour
}


```

Both forms of isWithinScope and hasScopeKey are identical and are provided for consistency with the two forms of the `use` method.

Detecting if you are within a Scope is really useful for unit testing.

Your unit tests can inject a ScopeKey and change your code can then change its behaviour when running within a unit test.

This can be easier then setting up a full mock framework.
